Hi

I am having difficulty understanding the following..

This works as expected...

: (setq Sum '(1 1 0))
-> (1 1 0)
: (set Sum (+ (cadr Sum) (caddr Sum)))
-> 1
: (rot Sum)
-> (0 1 1)
: (set Sum (+ (cadr Sum) (caddr Sum)))
-> 2
: (rot Sum)
-> (1 2 1)
: (set Sum (+ (cadr Sum) (caddr Sum)))
-> 3
: (rot Sum)
-> (1 3 2)
: (set Sum (+ (cadr Sum) (caddr Sum)))
-> 5
: (rot Sum)
-> (2 5 3)
: (set Sum (+ (cadr Sum) (caddr Sum)))
-> 8
: Sum
-> (8 5 3)

However, when I put it in a function...

(de Fibonacci (N)
   (let (Fib '(1 1 0))
      (do N
         (rot Fib)
         (set Fib (+ (cadr Fib) (caddr Fib))) )
   (car Fib) ) )

The results are something like a 'co routine or 'job... in that Fib as a
memory between calls and it is not re-initialized with the 'let as I
expected.

-> Fibonacci
: (Fibonacci 1)
-> 2
: (Fibonacci 1)
-> 3
: (Fibonacci 1)
-> 5
: (Fibonacci 1)
-> 8
..

The behavior I expected was

: (Fibonacci 3)
-> 5
.

Why?

/Lindsay

Reply via email to