delete symbol from context?

Started by nigelbrown, December 30, 2003, 04:33:48 PM

Previous topic - Next topic

nigelbrown

Can a symbol be deleted from a context some way?

The reason for doing so may be that if a symbol is

created in a context before the same symbol is made global in main then the globalized symbol is never global to that context (can be accessed by MAIN:symbol of course). If that symbol could be deleted from the context symbol table then, presumably, the global symbol could be seen. This would allow cleaning up and in extreme cases perhaps save some memory.

Could a whole context be deleted (currently they are protected in main) once no longer needed eg a context that does only initialization stuff?

This reminds me of the FORTH forget of some of its dictionary.



Nigel

Lutz

#1
yes, you can:



(set 'CTX:var 123)  ;; creates context CTX and a symbol 'var



(symbols CTX) => (CTX:var) ;; one symbol in context CTX



(delete 'CTX) => nil ;; cannot delete context because it has a symbol



(delete 'CTX:var) => true ;; you can delete the variable



(delete 'CTX) => true ;; now you can delete the context, because its empty





Variables referenced in other expressions will be replaced with 'nil' when deleted.



Imagine several variables:



(set 'CTX:var1 123)

(set 'CTX:var2 345)



(symbols CTX) => (CTX:var1 CTX:var2)



(map delete (symbols CTX)) => (true true) ;; delete all vars in a context



(delete 'CTX) => true ;; can delete the empty context



Lutz

nigelbrown

#2
Thanks Lutz