variable capture.

Q&A's, tips, howto's
Locked
PaipoJim
Posts: 20
Joined: Fri Jun 03, 2005 3:21 pm
Location: Oregon

variable capture.

Post by PaipoJim »

In section13 - "Dynamic and lexical scoping" of the "newLISP Users Manual and Reference v.8.6.0 rev-1" it states:
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
Posts: 58
Joined: Thu Apr 14, 2005 1:12 am

Post by statik »

I agree. Its a bit unclear.
-statik

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

Post by Lutz »

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

Lutz

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

Post by Lutz »

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

Lutz

Locked