Curious behaviour using $

Started by ale870, July 25, 2009, 08:14:46 AM

Previous topic - Next topic

ale870

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

newBert

#1
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
>
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

ale870

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

Lutz

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

ale870

#4
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?
--

Lutz

#5
These are currently created during startup:



http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols">http://www.newlisp.org/downloads/newlis ... em_symbols">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.