Weird behavior for function `symbol?`

Started by rickyboy, January 10, 2015, 06:51:47 PM

Previous topic - Next topic

rickyboy

Running 10.6.0 on FreeBSD.



Check this:


> (context 'Another)
Another
Another> (symbol? 'x)
true
Another> (symbol? 'Try:x)

ERR: context expected in function symbol? : Another:Try

But the same calls work in MAIN.


> (symbol? 'x)
true
> (symbol? 'Try:x)
true

Why?
(λx. x x) (λx. x x)

Lutz

#1
Implicit context creation of name1 when reading name1:name2 only happens when name1 doesn't exist before as a normal variable in either MAIN or the name space where trying to use it as a context. If already existing as a normal variable symbol in MAIN or the current context an error is thrown.



In the following three examples it works in the first because Try does not exist. In the second and third example it throws an error because Try already exists as a normal variable (not a context) and also as a normal variable does not contain a context.



newLISP v.10.6.0 32-bit on OSX IPv4/6 UTF-8 libffi, options: newlisp -h

> (context 'Another)
Another
Another> (symbol? 'x)
true
Another> (symbol? 'Try:x) ; <— Try never mentioned before, context is created
true
Another>


newLISP v.10.6.0 32-bit on OSX IPv4/6 UTF-8 libffi, options: newlisp -h

> Try ; <— creates the symbol Try
nil
> (context 'Another)
Another
Another> (symbol? 'x)
true
Another> (symbol? 'Try:x)

ERR: context expected in function symbol? : MAIN:Try
>


newLISP v.10.6.0 64-bit on BSD IPv4/6 UTF-8, options: newlisp -h

> (context 'Another)
Another
Another> Try ; <— creates the symbol Try
nil
Another> (symbol? 'x)
true
Another> (symbol? 'Try:x)

ERR: context expected in function symbol? : Try
>


Only the context primitive can convert an existing variable symbol into a context.

rickyboy

#2
Thank you, Lutz!
(λx. x x) (λx. x x)