Page 1 of 1

Not Switching Contexts and a Constant Question

Posted: Sat Feb 06, 2010 2:50 am
by m i c h a e l
I noticed while using net-eval that context doesn't actually switch the context:

Code: Select all

> (net-eval "localhost" 4711 "(context 'C)" 1000)
C
> (net-eval "localhost" 4711 "(context)" 1000)
MAIN
> _
This is similar to what happens when using eval in the following way:

Code: Select all

> (dolist (ea '((context 'C) (constant 'v 8) (context MAIN))) (eval ea))

ERR: symbol not in current context in function constant : MAIN:v
> _
Also, shouldn't constant work like set in the following example?

Code: Select all

> (new Class 'Thing)
Thing
> (set 'Thing:attribute 1)
1
> (constant 'Thing:attribute 1)

ERR: symbol not in current context in function constant : Thing:it
> _
If you want to use constants for named indexes (a good idea), then you're forced to define your class within a context. This is a must for large, complex classes, but for simple classes, I like the minimalism of defining within the MAIN context.

m i c h a e l

Re: Not Switching Contexts and a Constant Question

Posted: Sun Feb 07, 2010 1:25 pm
by Lutz
- first example -

newLISP server internally does a reset, stack cleanup and reinitialization of all signals after each client connection. If running a stateful server only the contents of variables is kept.

But it will switch, you can see when packing both expressions in one transaction:

Code: Select all

> (net-eval "localhost" 4711 "(begin (context 'C) (context))")
C
 
> (net-eval "localhost" 4711 "(context? C)")
true
You also can see, it kept the context.

- second and third example -

You have to be inside the context to make symbols constant. This is documented in the reference for 'constant'.

Re: Not Switching Contexts and a Constant Question

Posted: Mon Feb 08, 2010 2:55 am
by m i c h a e l
Thanks, Lutz. This topic came up while working on the new FOOP video. Or more specifically, the new line-commander (the code that simulates typing on the command-line). In line-commander, I evaluate each line one-by-one to get the result we see. I noticed that context didn't switch contexts when doing it this way (the second example). In order to cope with this, I began "faking it" and evaluating all expressions in MAIN by fully qualifying the symbols. Unfortunately, the problem with using constant for named indexes popped up as a result. At this point, I'm just defining them with setq.

m i c h a e l