Question about the "def-new" function.
Posted: Tue Oct 25, 2005 9:24 pm
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).
Great! So let's do it from a variable:
So far so good, let's set the variable programatically:
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?
-
Code: Select all
> (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"))
Code: Select all
> (set 'myVar 'myCtx2:myCtx2)
myCtx2:myCtx2
> (def-new 'myProc myVar)
myCtx2:myCtx2
> (context myCtx2)
myCtx2
myCtx2> (myCtx2)
hi
"hi"
Code: Select all
> (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
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?
-