I am trying to write a function that creates a number of contexts of the same type all with the same default function, a sort of class constructor method, if you will. It seems possible but I can't get it to work (at least without a macro).
> (define (myProc) (println "hi"))
(lambda () (println "hi"))
> (def-new 'myProc 'myCtx:myCtx)
myCtx:myCtx
> (myCtx:myCtx)
hi
"hi"
> (context? myCtx)
true
> myCtx:myCtx
(lambda () (println "hi"))
Great! So let's do it from a variable:
> (set 'myVar 'myCtx2:myCtx2)
myCtx2:myCtx2
> (def-new 'myProc myVar)
myCtx2:myCtx2
> (context myCtx2)
myCtx2
myCtx2> (myCtx2)
hi
"hi"
So far so good, let's set the variable programatically:
> (set 'myVar (sym (append "myCtx" (string 3) ":myCtx" (string 3))))
myCtx3:myCtx3
> (def-new 'myProc myVar)
myCtx3:myCtx3
> (context? myCtx3)
nil
> myCtx3:myCtx3
context expected : myCtx3
How do I set myVar so that "def-new" evaluates it in the same way as when I set it to 'myCtx2:myCtx2 explicitly?
Do I indeed need a macro for this or is it something I'm just not getting about symbols and newLISP's evaluation of variables?
-