Page 1 of 1
Reference passing question
Posted: Mon Jul 07, 2008 12:57 pm
by Jeff
How useful can reference passing using default functors be if we cannot define contexts locally?
Limiting context creation to global symbols puts a hard wall on the complexity of an application. What if I do not know ahead of time how many contexts I will need?
I can create a gensym-type function that will create a new, unique symbol in MAIN whenever I need, but that pollutes the global namespace.
Is there any way to dynamically generate namespaces based on runtime conditions?
Posted: Mon Jul 07, 2008 1:39 pm
by Lutz
you can use this:
Code: Select all
(define (create-context-from-name str)
(sym str (sym str MAIN))
)
(create-context-from-name "Foo") => Foo:Foo
creates a context with default functor
Posted: Mon Jul 07, 2008 1:48 pm
by Jeff
Yes, and that still pollutes my global namespace. I don't see why there is such an issue over being able to create contexts out of local variables. It may not be the most efficient way for all programs, but it should still be there for those that
do need it.
Also, using the new dictionary contexts, I seem to be having difficulty with this:
Code: Select all
(define foo:foo)
(foo "x" 0)
(foo "x" (+ 1 (foo "x"))) ; => ERR: value expected in function + : (foo "x")
Any idea why that doesn't work?
Posted: Mon Jul 07, 2008 2:03 pm
by Lutz
I don't see why there is such an issue over being able to create contexts out of local variables.
Code: Select all
(define (foo x)
(let (ctx)
(println "ctx:" ctx)
(context 'ctx)
(set 'ctx:x x)
(println "current context:" (context))
(println "symbols in ctx: " (symbols ctx))
(println "ctx:x: " ctx:x)
(println "x:" x)
(delete 'ctx)
))
> (foo 999)
ctx:nil
current context:ctx
symbols in ctx: (x)
ctx:x: 999
x:999
true
>
You still can do it, if you delete the context explicitly before exiting the function.
Code: Select all
(foo "x" (+ 1 (foo "x"))) => gives error
(foo "y" (+ 1 (foo "x"))) => would work
first should work too, I will look into it. Looks like we need yet another update of 9.4.1 to 9.4.2 :-((
Posted: Mon Jul 07, 2008 2:11 pm
by Jeff
That's great. That is something that I really needed.