behaviour of (symbols)

For the Compleat Fan
Locked
Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

behaviour of (symbols)

Post by Fanda »

There is one thing that I don't understand about function (symbols). Run this as a script:

Code: Select all

(set 's1 (symbols))

(define (f x)
  (let (y 2)
    (+ x y)))

(set 's2 (symbols))

(println (difference s2 s1 true))

(exit)
Output that I get is: (f s2 x y)

My question is: Why 'x' or 'y'? Function 'f' was never called and even if it was - 'x' or 'y' are only temporary symbols.

Thanks for answering, Fanda

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

'x' and 'y' are created in the symbol table with contents 'nil, when loading the program. The symbols are created so they can be referenced when loading the code and translating it into an internal format.

'x' and 'y' are locally modified when exeuting 'f'; when leaving the function 'f' they get their old values back. Their values are temporary but the symbols itself are not.

Lutz

Locked