dynamic 'local' symbols in functions, and the symbol table

Q&A's, tips, howto's

dynamic 'local' symbols in functions, and the symbol table

Postby JohnE » Sat Jan 08, 2011 11:39 pm

I have only just realised that the temporary symbols such as the x in:
(dolist (x some-list) ... ) are actually persistent and remain to be listed later by (symbols). If this dolist is in a definition, then subsequently deleting 'x results in the definition failing next time it is used. If there was an existing x with a value other than nil, then it remains unchanged, as expected, so it isn't obvious that one would otherwise have been created.

Code: Select all
> (50 5 (symbols))
(add address amb and append)
> (define (scratch) (dolist (add-it '(x y z)) "done"))
(lambda ()
 (dolist (add-it '(x y z))
  "done"))
> (50 5 (symbols))
(add add-it address amb and)
> (scratch)
"done"
> (delete 'add-it)
true
> (scratch)

ERR: symbol is protected in function dolist : nil
called from user defined function scratch
>


This might be known by all, but it was news to me. I was idly picking off symbols clutter, some with nil values, then discovered I had ruined several definitions. I have been keeping snapshots using (save) so it was easily repaired. (It is because of the snapshots that I was clearing the redundant symbols, to speed up save and load. It is so easy to switch between several independent projects using save & load.)

Since I can't remember what might actually be used in a definition somewhere, I shall leave them all alone from now on. Maybe I should just settle on one name for this 'tempory' symbol, and always use that. 'Temp' might be a good name!

Regards, John

(Edited to add code)
JohnE
 
Posts: 14
Joined: Thu Nov 01, 2007 5:08 pm

Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest

cron