Page 1 of 1

Curious behaviour using $

Posted: Sat Jul 25, 2009 3:14 pm
by ale870
Hello,

true this code:

Code: Select all

(context 'NEWCTX)
(setq $myvar 123)

(context MAIN)
$myvar
As you can see, using a variable with the prefix "$", makes the variable "global".
Is it an implicit context binding?

Posted: Sun Jul 26, 2009 10:40 am
by newBert
Curious indeed !

Code: Select all

newLISP v.10.1.1 on Win32 IPv4, execute 'newlisp -h' for more info.

> (context 'NEWCTX)
NEWCTX
NEWCTX> (set '$myvar 123)
123
NEWCTX> (context MAIN)
MAIN
> $myvar
123
> NEWCTX:$myvar
nil
>
but ...

Code: Select all

newLISP v.10.1.1 on Win32 IPv4, execute 'newlisp -h' for more info.

> (setq NEWCTX:$myvar 123)
123
> $myvar
nil
> NEWCTX:$myvar
123
>

Posted: Sun Jul 26, 2009 10:43 am
by ale870
Funny!!!

I think it could be related to "special variables" management ($0, $1, etc...) for parsing.

Lutz, I think this bug (or feature? :-) ) should be investigated a little bit more.

Posted: Sun Jul 26, 2009 12:10 pm
by Lutz
It is an undocumented feature, by-product of system variables management.

Be aware that these variables don't get serialized when using the 'save' or 'source' function on the enclosing context. E.g. (save "mystuff.lsp") will serialize MAIN and all other namespaces, but will not serialize symbols starting with the $ character. On the other contrary, context symbols starting with $ will get saved with their contents. Perhaps the latter should be disabled.

Posted: Sun Jul 26, 2009 1:20 pm
by ale870
Thank you Lutz.

Have you planned some special area to use those variables?
Did you made them to supply something "special" for the future?

Can we freely use them, or you can give us some guidelines?

Posted: Sun Jul 26, 2009 2:13 pm
by Lutz
These are currently created during startup:

http://www.newlisp.org/downloads/newlis ... em_symbols

Others might be added in the future. Do with them whatever you like. Personally I never create my own, but don't want to limit anybody else in doing so.