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?
you can use this:
(define (create-context-from-name str)
(sym str (sym str MAIN))
)
(create-context-from-name "Foo") => Foo:Foo
creates a context with default functor
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:
(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?
Quote
I don't see why there is such an issue over being able to create contexts out of local variables.
(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.
(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 :-((
That's great. That is something that I really needed.