Unexpected error

Started by alex, December 14, 2005, 10:40:10 PM

Previous topic - Next topic

alex

Unexpected error. See below:
Quote
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

#1
This looks strange to me too:


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

#2
When newLISP reads:



ctx> (symbol? x)


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



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

#3
Quoteit first translates the code and creates a 'x' symbol in the current context ctx.


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

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



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