(context 'CTX) feature

For the Compleat Fan
Locked
Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

(context 'CTX) feature

Post by Dmi »

Found interesting "feature":

Code: Select all

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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:

Code: Select all

> (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:

Code: Select all

(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
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

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

Locked