SICPèªæ¸ä¼ãä¼ã¿ã®åï¼in æ¸è°·ï¼
- ä¼å ´ã確ä¿ã§ããªãã£ãã®ã§naoya_tããã®è¿æä¼ã«
- ã§ãæ±äº¬ããã®åå ã¯äºäººï¼æ³£ï¼
- æéè¨å®ã«ã¡ãã£ã¨ç¡çããã£ã
- Schemerã¯Lisperã§ã¯ãªã
- å帰ã¯ãããxyzzyçéã§è©±é¡ã«
- OCamlã¯ãµã¤ãã£ã½ã
- naoya_tããã®ãå¸æã§å«è¶åºã«
- 横ã§äºäººãæ¿ã話ããã¦ãã®ãã¼ã¼ã£ã¨èãã¦ããã¾ãã
- çµå±ãã¢ããã³ã¹ãSICPèªæ¸ä¼ã«ãªã£ã¡ããããSICPãæã£ã¦ãã¦ãªãã£ãã®ã¯ç§ã ã
- åé¡ã®çãã¯ç´ã«æ¸ããå®è¡ããã®ã¯è»å¼±
- æ¸ããã³ã¼ããå®è¡ã§ããé»æ¿ã¨ã
- naoya_tããã¯SICPãèªã¿çµãã¦æå¾ã®åé¡ããã£ã¦ã
- Objective-C/Cocoaã§Schemeãå®è£
ãã¦ãã¨ã®ãã¨
- ãªãã¸ã§ã¯ãã§call/ccãå®è£ ããã®ã¯ç¡çã£ã½ã
- SICPã ãã§ä½ããã®ã¯è¨èªå¦çç³»ããã
- Gaucheãå®ç¨çãªã®ã¯Common Lispã®èãæ¹ãåãå ¥ãã¦ãããã
- ååä»ãletã®ç°å¢ãã©ãå®è£ ããããã¡ã¤ã³ã®è©±é¡ã«
以ä¸ã復ç¿
(define (fib n) (let fib-iter ((a 1) (b 0) (count n)) (if (= count 0) b (fib-iter (+ a b) a (- count 1)))))
âããã
ããããâ
(define (fib n) (let ((fib-iter '*unassigned*)) (set! fib-iter (lambda (a b count) (if (= count 0) b (fib-iter (+ a b) a (- count 1))))) (fib-iter 1 0 n)))
追è¨
shiroããã®ãææã«ããä¿®æ£
R5RSã«ããã¨âã¿ããã§ã
(define (fib n) ((letrec ((fib-iter (lambda (a b count) (if (= count 0) b (fib-iter (+ a b) a (- count 1)))))) fib-iter) 1 0 n))
âã§ãåä½ãk
(define (fib fib-iter) ((letrec ((fib-iter (lambda (a b count) (if (= count 0) b (fib-iter (+ a b) a (- count 1)))))) fib-iter) 1 0 fib-iter))