newLISP Fan Club

Forum => newLISP in the real world => Topic started by: ale870 on July 25, 2009, 08:14:46 AM

Title: Curious behaviour using $
Post by: ale870 on July 25, 2009, 08:14:46 AM
Hello,



true this code:



(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?
Title:
Post by: newBert on July 26, 2009, 03:40:36 AM
Curious indeed !


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 ...


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

> (setq NEWCTX:$myvar 123)
123
> $myvar
nil
> NEWCTX:$myvar
123
>
Title:
Post by: ale870 on July 26, 2009, 03:43:49 AM
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.
Title:
Post by: Lutz on July 26, 2009, 05:10:59 AM
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.
Title:
Post by: ale870 on July 26, 2009, 06:20:45 AM
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?
Title:
Post by: Lutz on July 26, 2009, 07:13:07 AM
These are currently created during startup:



http://www.newlisp.org/downloads/newlisp_manual.html#system_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.