Code: Select all
(define fibs
(lazy-cat '(0 1) (map + fibs (rest fibs))))
(fibs 10) ; ==> 55
Code: Select all
(define fibs
(lazy-cat '(0 1) (map + fibs (rest fibs))))
(fibs 10) ; ==> 55
Code: Select all
(define (fibo:fibo)
(if-not fibo:m
(setq fibo:m '(0 1)))
(pop (push (apply + fibo:m) fibo:m -1))
(last fibo:m))
(fibo) ;=> 1
(fibo) ;=> 2
(fibo) ;=> 3
(fibo) ;=> 5
(fibo) ;=> 8
Code: Select all
(define (fib)
(pop (push (eval (last fib)) (last fib) -1) 1)
(+ 0 1))
(fib) ;=> 2
(fib) ;=> 3
(fib) ;=> 5
(fib) ;=> 8
fib ;=> (lambda () (pop (push (eval (last fib)) (last fib) -1) 1) (+ 3 5))
Code: Select all
(define-macro (memoize mem-func func)
(set (sym mem-func mem-func)
(letex (f func c mem-func)
(lambda ()
(or (context c (string (args)))
(context c (string (args)) (apply f (args))))))))
(memoize fibonacci
(lambda (n)
(if(< n 2) 1
(+ (fibonacci (- n 1))
(fibonacci (- n 2))))))
(fibonacci 80) ;=> 37889062373143906