dynamic 'local' symbols in functions, and the symbol table
Posted: 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.
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)
(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
>
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)