Bug of (context Foo)?

Started by limux, November 01, 2013, 09:21:35 AM

Previous topic - Next topic

limux

the code

(set 'Foo:name "limux")
(context Foo)

is ok.



but
(context Foo)
(set 'Foo:name "limux")

is bad.



I think the bug is if you run the "(context Foo)" first, then "(set 'Foo:name "limux")"

will always report error.



Great thanks for more details about context or demo code!

conan

#1
You forgot to quote Foo on your second example:



(context 'Foo)


Other than that I don't see anything wrong with that. What error are you seeing?

limux

#2
I am not forgot the quote, I just do that.



Because (context Foo) is the first code line.  It's surely failed.

The question is once that code be evaluted, I wonder why the (set 'Foo:name nil) also will be failed.

but in a new clean newlisp instance, the (set 'Foo:name nil) will be ok without evaluated (context Foo).

Lutz

#3
The evaluated argument of context has to be either a symbol or a context.



If Foo is not a context yet, Foo evaluates to nil and nil is not a context. To make a context out of Foo it must be given quoted as a symbol.


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

> (context? Foo)    
nil
> (context Foo)

ERR: symbol or context expected in function context : Foo
> (context 'Foo)
Foo
Foo> (context MAIN)
MAIN
> Foo  ; variable Foo evaluates to context Foo
Foo
> (context? Foo)  ; no quote necessary because variable Foo contains context Foo
true
> (context Foo)  ; switches to existing context Foo
Foo
Foo> (context MAIN)
MAIN
> (set 'ctx Foo)  ; the variable ctx contains a context
Foo
> (context ctx)
Foo
Foo> (context MAIN)
MAIN
> (set 'Bar:var 123)  ; context Bar with symbol var in it gets created
123
> (context? Bar)
true
> (context Bar)
Bar
Bar> (context MAIN)
MAIN
>

limux

#4
Please see detailed the following code and is there any issue?



> (set 'Foo1:var1 nil)
nil
> (context? Foo1)
true
> (context Foo2)

ERR: symbol or context expected in function context : Foo2
> (set 'Foo2:var2 nil)

ERR: context expected in function set : Foo2
> (context? Foo2)
nil
> (set 'Foo2:var2 nil)

ERR: context expected in function set : Foo2

> (context? Foo2)
nil

>


Thanks for your reply. I think you are not understand my true ideas.



Before I define context Foo1, Foo1 is nil. (set 'Foo1:var1 nil) will surely define the Foo context,

then (context Foo1) is ok and (context2 Foo2) will return true.

See Foo2, It is also not defined, (context? Foo2) is nil and (context Foo2) will show errors. then

how can I define the Foo2 just after (context Foo2) which make some error?

(set 'Foo2:var2 nil) will always failed. This is my messes! If Foo2 has even not defined and you

evaluate (context Foo2) with some error, you will never define the context Foo2 by

"(set 'Foo2:var2 nil)". So I think it's a bug, perhaps!



I come from china, I love lisp but my english is a little bad, thanks your guys!

Lutz

#5
The implicit creation of a new context via the (set 'Foo:name ...) statement only works when the symbol hasn't been introduced before. Once the symbol exists, only the context function can be used to make a context out of it:


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

> Foo   ; Foo has now been "seen" and an ordinary symbol Foo is created
nil
> (set 'Foo:name 123) ; Foo cannot be converted to a context via set

ERR: context expected in function set : Foo
> (context 'Foo) ; only the context function allows conversion of ordinary vars into contexts
Foo
Foo> (context MAIN)
MAIN
>

> (set 'Bar:name 456) ; implicit creation of context Bar works, because it hasn't been seen before
456
>


This is a safeguard for not screwing up code entered before by accidental  (set 'Foo:name ...) statements. All context creating statements like (set 'Foo:name ...) or better (define Foo:name ...) should be at the beginning of your program. The best is to create and introduce all contexts in the MAIN module.



If you wanted, you still could force (set 'Foo:name ...) to work by deleting the smbol before:


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

> Foo
nil
> (delete 'Foo)  ; symbol Foo is deleted again
true
> (set 'Foo:name 123)  ; now implicit context creation of Foo works
123

limux

#6
I see, great thanks!



Foo introduced the "Foo" as a symbol with value of nil.

and (context Foo) also implicit introduce the symbol "Foo", although throw a error

"ERR: symbol or context expected in function context : Foo",



Is it right?



I should to read the source of newLisp I think.

limux

#7
even (symbol? Foo) will implicit introduce a symbol. That is newLisp style!

Lutz

#8
(symbol? Foo) would check the contents of Foo, not the symbol Foo itself. But yes, the moment any code is loaded, symbols are created the first time they occur.

limux

#9
Very thanks and Best Regards.