Page 1 of 1

Unexpected error

Posted: Thu Dec 15, 2005 6:40 am
by alex
Unexpected error. See below:
G:\>newlisp

newLISP v.8.7.2 on Win32 MinGW, execute 'newlisp -h' for more info.

> (setq zzz:aaa 1)
1
> (context? zzz)
true
> (exit)

G:\>newlisp
newLISP v.8.7.2 on Win32 MinGW, execute 'newlisp -h' for more info.

> (context? zzz)
nil
> (setq zzz:aaa 1)

context expected in function setq : zzz

>
It is not normal, I think.

Posted: Thu Dec 15, 2005 6:55 am
by Fanda
This looks strange to me too:

Code: Select all

newLISP v.8.7.4 on Win32 MinGW.

> (context 'ctx)
ctx
ctx> (symbols)
()
ctx> (symbol? x)
nil
ctx> (symbols)
(x)
ctx> x
nil
ctx> 
Fanda

Posted: Thu Dec 15, 2005 1:04 pm
by Lutz
When newLISP reads:

Code: Select all

ctx> (symbol? x)
it first translates the code and creates a 'x' symbol in the current context ctx.

Code: Select all

> (context? zzz) 
nil 
> (setq zzz:aaa 1) 

context expected in function setq : zzz 

> 

When newLISP reads the expression (context? zzz), it does not find the symbol 'zzz' and creates it in the current context. When you do a (setq zzz:aaa 1) it finds that 'zzz' is not a context symbol but a normal symbol and throws an error.

newLISP creates symbols in the current context if they don't exist.

Lutz

ps: there are some chapters about this in the manual.

Posted: Fri Dec 16, 2005 4:36 am
by alex
it first translates the code and creates a 'x' symbol in the current context ctx.

Code: Select all

> (context 'ctx)
ctx
ctx> (symbol? x)   #symbol 'x' creates
nil
ctx> (symbols)      #Yes, symbol 'x' exists
(x)
ctx> (symbol? x)   #No, we have no symbol 'x' !?
nil
ctx>
Why?!

Posted: Fri Dec 16, 2005 10:28 am
by Lutz
The function 'symbol' evaluates it's argument first. In (symbol? x) you are asking if the contents of 'x' is a symbol. You have to quote it:

Code: Select all

> (symbol? x)
nil
> (symbol? 'x)
true
> (set 'y 'z)
z
> (symbol? y)
true
> y
z
evaluation is a central topic in newLISP (and any LISP), there is a chapter about this in the manual you could read.

Lutz