Here is a changed working version and some comments:
Code: Select all
(context 'MyContext)
(set 's "hi there")
(context MAIN)
(define (func ctx w)
(println "inside function, context is " ctx " and symbol value of w is " w)
(println "inside function " (eval (sym (name w) ctx)))
; or in versions after 8.7.1 you also can do
;(println "inside function " (context ctx (name w)))
)
(println "MAIN:s is " s) ; sin MAIN hasn't been set yet so it is nil
(println "MyContext:s is " MyContext:s)
(println (func MyContext 's)) ; s has to be passed as a symbol, else nil gets passed
The main problem was the function call (fun ....) the s has to be passed as a symbol.
The other problem was in the line:
Code: Select all
(println "inside function " ctx:w)
Only ctx can be a variable holding MyContext. The w will always be w, so from ctx:w you get MyContext:w but not MyContext:s
Lutz
ps: perhaps this should be posted in the last newLISP topic-group?