creating context inside macro
Posted: Mon Aug 28, 2006 4:35 pm
This may be a dumb thing to do:
And it crashes newLISP.exe.
But the following seems to work a little better:
Basically I want to be able to create a context and a function and call that function in one expression.
Code: Select all
(define-macro (foo1 ctx1 arg1)
(context ctx1)
(define (foo1 arg1)
(setq var1 arg1)))
(foo1 fooctx1 "hello1")
Another thing is that I wanted to create foo1 in foo1 context. But I guess while running the macro in MAIN context, creating context inside the running macro and defining new function does not make the new ones go into the newly created context -- they instead go to MAIN. But still that crashes, so I don't know.> (debug (foo1 fooctxt1 "hello1"))
-----
(define-macro (foo1 ctx1 arg1)
#(context ctx1)#
(define (foo1 arg1)
(setq var1 arg1)))
[-> 3 ] s|tep n|ext c|ont q|uit > ctx1
fooctxt1
[-> 3 ] s|tep n|ext c|ont q|uit > s
-----
(define-macro (MAIN:foo1 MAIN:ctx1 MAIN:arg1)
#(context MAIN:ctx1)#
(define (MAIN:foo1 MAIN:arg1)
(setq MAIN:var1 MAIN:arg1)))
RESULT: fooctxt1
[<3> s
-----
(define-macro (MAIN:foo1 MAIN:ctx1 MAIN:arg1)
(context MAIN:ctx1)
#(define (MAIN:foo1 MAIN:arg1)
(setq MAIN:var1 MAIN:arg1))#)
[-> 3 fooctxt1] s|tep n|ext c|ont q|uit > s
***newLISP Crashes here *****
C:\Documents and Settings\Owner>
But the following seems to work a little better:
Code: Select all
(define-macro (foo1 ctx1 arg1)
(setq FOO1 (context ctx1))
(define (FOO1:foo1 FOO1:arg1)
(setq FOO1:var1 FOO1:arg1)))