Implicit creation of contexts not working newlisp 10.5.3

Started by bharath_g, September 08, 2013, 12:09:50 AM

Previous topic - Next topic

bharath_g

In the newlisp manual in the "Creating contexts" section it is mentioned that contexts are created

implicitly when referring to a context that does not exist.

This is working in general but if i use a single character as a context name then it fails with the following error

If i try to do this

(define (D:foo x y)
  (+ x y))

It fails with error
Quote ERR: context expected in function define : D


It works ok if i just use a 2 character name for the context like this

(define (DC:foo x y)
  (+ x y))

JohnE

Hello,



I've just tried it:



-------------------------------

newLISP v.10.5.1 32-bit on Win32 IPv4/6 libffi, options: newlisp -h



> (define (D:foo x y) (+ x y))

(lambda (x y) (+ x y))

> (D:foo 3 5)

8

>

-------------------------------



However, if D is already defined as something else, it fails.  I think that's reasonable.

This is what I did after the above test:



------------------

> (delete 'D)

true

> (D:foo 3 5)           <-----------  check if it's gone



ERR: context expected : D         <-----------  Yes, it's gone

>

>

> (set 'D 0)          

0

> D

0

> (define (D:foo x y) (+ x y))



ERR: context expected in function define : D             <----------- D already exists as something else

>

---------------------------------





John

Lutz

That is correct, it failed for bharath_g, because the variable already existed. But you can convert an already existing variable to a context using the context function:


> (set 'D 123)
123
> (define D:foo 456)

ERR: context expected in function define : D
> (context 'D "foo" 456)     ;<-- but this will work
456
> D:foo
456
>


it's only the implicit creation which is not allowed on existing variables. It also works for functions:


> (set 'D 123)
123
> (context 'D "foo" (lambda (x y) (+ x y)))
(lambda (x y) (+ x y))
> (D:foo 3 4)
7
>