variable capture.

Started by PaipoJim, June 15, 2005, 07:45:57 PM

Previous topic - Next topic

PaipoJim

In section13 - "Dynamic and lexical scoping" of the "newLISP Users Manual and Reference v.8.6.0 rev-1" it states:


Quote
Note that by passing quoted symbols to a user-defined function, a potential name clash may occur if the same variable name is used as a function parameter:



(define (inc-symbol x y) (inc x))



(set 'y 200)



(inc-symbol 'y 123) => 246



y                   => 999   ; y is still 999



When trying to modify the content of 'y inside the function it modifies 123 to 124 not 200 to 323. This variable capture is a disadvantage of dynamic scoping when passing symbol references to user-defined functions.


First, shouldn't the last line be:



y       => 200; y is still 200 ?



Secondly, as currently defined, the inc-symbol invocation should read:



(inc-symbol 'y 123) => 124



The function inc-symbol doesn't internally increment y by 123 because the primitive function inc is not being passed an optional increment value and is defaulting to 1; and is not in and of itself a result of the passed reference symbol 'y getting hijacked by the function parameter y.



If inc-symbol is defined as:



(define (inc-symbol x y) (inc x y))



then it's invocation would yield => 246 but that would not be in agreement with the text which follows the example.



In any event, this section of the manual as currently written is confusing to the student.

statik

#1
I agree. Its a bit unclear.
-statik

Lutz

#2
Oops, this section is competely screwed up, thanks for letting me know. I will post a corrected reviision shortly.



Lutz

Lutz

#3
rev-2 of the 8.6.0 manual is posted here: http://newlisp.org/downloads/newlisp_manual.html">http://newlisp.org/downloads/newlisp_manual.html . A PDF version not until I am home again, beginning July.



Lutz