コードは以下のとおり。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-trace) | |
(lambda (f) | |
(lambda (n) | |
(format #t "\; call with : ~a\n" n) | |
(f n)))) | |
(time ((Y (compose (make-trace) fib)) 5)) | |
;(time ((Y (compose (make-trace) fib)) 5)) | |
; real 0.000 | |
; user 0.000 | |
; sys 0.000 | |
; call with : 5 | |
; call with : 4 | |
; call with : 3 | |
; call with : 2 | |
; call with : 1 | |
; call with : 0 | |
; call with : 1 | |
; call with : 2 | |
; call with : 1 | |
; call with : 0 | |
; call with : 3 | |
; call with : 2 | |
; call with : 1 | |
; call with : 0 | |
; call with : 1 | |
8 | |
(time ((Y (compose (make-memoize)(compose (make-trace) fib))) 5)) | |
;(time ((Y (compose (make-memoize) (compose (make-trace) fib))) 5)) | |
; real 0.000 | |
; user 0.000 | |
; sys 0.000 | |
; call with : 5 | |
; call with : 4 | |
; call with : 3 | |
; call with : 2 | |
; call with : 1 | |
; call with : 0 | |
8 | |
おもしろいな~。
追記
;(compose hoge (compose fuga ... は (compose hoge fuga ... で良かった。(time ((Y (compose (make-memoize)(make-trace) fib)) 10))
;(time ((Y (compose (make-memoize) (make-trace) fib)) 10))
; real 0.000
; user 0.000
; sys 0.000
; call with : 10
; call with : 9
; call with : 8
; call with : 7
; call with : 6
; call with : 5
; call with : 4
; call with : 3
; call with : 2
; call with : 1
; call with : 0
89
0 件のコメント:
コメントを投稿