Curious behaviour using $

Q&A's, tips, howto's
Locked
ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Curious behaviour using $

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

newBert
Posts: 156
Joined: Fri Oct 28, 2005 5:33 pm
Location: France

Post 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
>
BertrandnewLISP v.10.7.6 64-bit on Linux (Linux Mint 20.1)

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

Locked