I noticed while using net-eval that context doesn't actually switch the context:
> (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:
> (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?
> (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
- 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:
> (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'.
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