Unexpected error

Pondering the philosophy behind the language
Locked
alex
Posts: 100
Joined: Thu Mar 10, 2005 2:27 pm
Location: Russia

Unexpected error

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

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post 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

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

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

alex
Posts: 100
Joined: Thu Mar 10, 2005 2:27 pm
Location: Russia

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

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

Post 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

Locked