Why local symbols are not deleted outside of their scope? For example, if one writes in REPL
(local (j) j)
and after that
(symbols)
then j is still there. Is it design, implementation or optimization issue?
Local symbols are not deleted outside of their scope.
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
It gets part of the symbol-table when the source gets loaded and translated. The Lisp VM only takes care of keeping an environment stack for it. The symbol itself could be used with a different value in another function. Consider the following code:
If any of the inner scopes would delete the symbol i, the outer scopes would be in trouble.
Code: Select all
(let (i 1)
(let (i 2)
(let (i 3)
(print i))
(print i))
(println i))
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
I do not know is it good, but it gives some supernatural abilities to the symbols.
Code: Select all
(set 'self-conscious-symbols
(lambda()
(if (not symbols1)
(set 'symbols1 (symbols)))
(let ((symbols2
(difference (symbols)
symbols1
'(i symbols1 symbols2 self-conscious-symbols))))
(dolist(i symbols2)
(set i (append "I am " (string i) ". I feel "
(string (apply amb
(difference symbols2
(list i))))
" is close."))))))
(self-conscious-symbols)
(seed (date-value))
(begin (self-conscious-symbols)
(println Sri-Aurobindo)
'(set 'i (list Maharishi
Sri-Chinmoy
Sai-Baba
Dalai-Lama)))
Once out of scope, they evaluate to nil. In fact, testing against a symbol - even one that is unassigned - creates the symbol, too. Remember the differences between variables, values, and symbols. Once out of scope, the symbol has no value and is not a variable anymore.
Symbols are also created in the context when functions are defined within the context.
It confused me at first too, but it is not generally a problem. The symbols being there adds no overhead (in fact, it reduces it when the symbols are reused).
Symbols are also created in the context when functions are defined within the context.
It confused me at first too, but it is not generally a problem. The symbols being there adds no overhead (in fact, it reduces it when the symbols are reused).
When I was first getting used to newlisp, I wanted it to throw an error if I used a symbol that had never been assigned a value (like Python). I even hacked a bit at the source, but wasn't able to find any easy way. Changing this behavior would probably be a major change to the system, requiring various other parts to change as well.
But this is just one of the many ways (including my wish for a newLint kind of tool) I would like the system to catch me doing dumb things, because I do them a lot.
But this is just one of the many ways (including my wish for a newLint kind of tool) I would like the system to catch me doing dumb things, because I do them a lot.
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact: