Evaluation of context symbols.

Started by PaipoJim, November 07, 2005, 12:44:19 PM

Previous topic - Next topic

PaipoJim

-

When using a function to generate symbols for the creation of contexts the following behavior can be observed:



> (define (build-sym x) (sym (string 'C x)))
(lambda (x) (sym (string 'C x)))

> (context (build-sym 2))
C2
C2> (context MAIN)
MAIN

> (context? (build-sym 2))
nil
 
> (context? (eval (build-sym 2)))
true

> (context (build-sym 2))
C2
C2>



I find this a little odd since context symbols evaluate to themselves and (build-sym 2) seems to be evaluating to a context the second time it is invoked.  But I think the following is really confusing:



C2> (context MAIN)
MAIN

> (setq ctx (build-sym 2))
C2
> (symbol? ctx)
true
> (context? ctx)
nil

> (setq cty C2)
C2
> (symbol? cty)
nil
> (context? cty)
true

>ctx
C2

>(symbols)
... ? @ C2 MAIN NaN? ...


 So will the real C2 please stand up...?  There is only one C2 in the symbol table but there is clearly a different C2 in 'ctx than there is in 'cty.  Except:



> (set ctx "something else")

symbol is protected in function set : C2

> (context ctx)
C2
C2>


It is obviously evaluating to a context here.  Should not (context? ctx) return true?  Or if it is really hiding the function (build-sym) underneath its "symbol" C2 then should not (lambda? ctx) return true?  The documentaion is not clear about out how these phantom symbols for contexts (sometimes) need another level of evaluation.

-

Lutz

#1
The cause of confusion is the fact that the symbol CT2 and the context CT2 look the same, so when the symbol C2 is evaluated we see "C2" agaion this time as a context. When doing:



(define (build-sym x) (sym (string 'C x)))
 
(build-sym 2) => C2 ; a symbol C2 is returned


The the C2 returned is a symbol containing nil. when you do:



(context (build-sym 2)) ; (1) -> make a context
(context? (build-sym 2) ; (2) -> returns nil


In (1) the context statement takes a symbol returned by (build-sym 2). In (2) you ask if a symbol is a context and correctly get nil as an answer.



In your last examples the following is happending:

> (setq ctx (build-sym 2) ; a symbol is assigneed to ctx
C2
> (symbol? ctx)  ; ctx contains the symbol C2
true
> (context? ctx) ; ctx contains asymbol not a context
nil

> (setq cty C2)  ; setq evaluates C2 to a context and assigns it
C2
> (symbol? cty) ; cty contains a context
nil
> (context? cty)
true

>ctx
C2


Lutz

PaipoJim

#2
Thanks Lutz.  I really needed to read the section on the eval function a little more carefully.