I'm a bit puzzled by that code too, but for different reasons:
Code: Select all
(set 'n 11)
(some-odd-nums
(fn (i) (println i " " n)))
I thought that
fn didn't evaluate anything, but just simply assembled a (kind of) list of unevaluated Lisp 'source'. So inside, the 'n' doesn't have any significance or value, any more than the 'i'?. And at the entry to the some-odd-nums function, the value passed to func is also a piece of unevaluated inert Lisp stuff. The 'n' is hibernating, and doesn't know where it will be when it's awakened. When the function is evaluated, the 'n' wakes up, looks for a value, and finds one?
In the same vein, can't you write this:
Code: Select all
(for (i 1 10)
(some-odd-nums (fn (i) (println i " " n ))))
because the 'i' inside the fn isn't the same 'i' as the loop iterator?
It may be that my puzzlement is with the way newLISP works, rather than with the way Scheme works... ;-)