Weird behavior for function `symbol?`

Q&A's, tips, howto's
Locked
rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Weird behavior for function `symbol?`

Post 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?
(λx. x x) (λx. x x)

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

Re: Weird behavior for function `symbol?`

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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: Weird behavior for function `symbol?`

Post by rickyboy »

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

Locked