(context 'CTX) feature

Started by Dmi, June 05, 2006, 12:52:04 PM

Previous topic - Next topic

Dmi

Found interesting "feature":
newLISP v.8.8.8 on linux, execute 'newlisp -h' for more info.

> (context 'CTX)
CTX
CTX> (context 'TEST)
TEST
TEST> (context 'CTX)
CTX
CTX> (symbols)
(CTX:TEST)
CTX> (set 'TEST:a 0)

context expected in function set : CTX:TEST

In other words, if we call (context 'SOMETHING) from inside the other context, we occasionally got a symbol in that context, that will interfere with new context's name.
WBR, Dmi

Lutz

#1
when you did (context 'TEST) inside context CTX when translating the statement it created a local symbol CTX:TEST first, then a context in MAIN.



The statement (set 'TEST:a 0) then referred to the local version of TEST. You could do the following instead:



> (context 'CTX)
CTX
CTX> (context 'MAIN:TEST)
TEST
TEST> (symbols 'CTX)
()
TEST> (context 'CTX)
CTX
CTX> (set 'TEXT:a 0)
0
CTX>


newLISP translates toplevel expressions first, then evaluates them. During the translation prrocess each symbol gets at first created in the local context, if it does not yet exists local or as a global. Avoid creating contexts from inside other contexts unless you are familiar with all the rules.



If you carry more than one context in a file just finish each with a (context 'MAIN) statement:



(context 'Foo)
...
...
(context MAIN)

(context 'Bar)
...
...
(context MAIN)

;etc


this way you are sure your context symbols only exist in MAIN and avoid ambigous situations.



Lutz

Dmi

#2
Thanx for explanation, Lutz!



(context 'MAIN:TEST) is a useful trick.

I found this when I've put two context definitions in one file sequentally without switching to MAIN.
WBR, Dmi