Page 1 of 1

Weird behavior for function `symbol?`

PostPosted: Sun Jan 11, 2015 2:51 am
by rickyboy
Running 10.6.0 on FreeBSD.

Check this:

Code: Select all
> (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.

Code: Select all
> (symbol? 'x)
true
> (symbol? 'Try:x)
true

Why?

Re: Weird behavior for function `symbol?`

PostPosted: Sun Jan 11, 2015 4:15 am
by Lutz
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.

Code: Select all
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>

Code: Select all
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
>

Code: Select all
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.

Re: Weird behavior for function `symbol?`

PostPosted: Mon Jan 12, 2015 4:30 am
by rickyboy
Thank you, Lutz!