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?
Reference passing question
you can use this:
creates a context with default functor
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
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:
Any idea why that doesn't work?
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")
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
>
Code: Select all
(foo "x" (+ 1 (foo "x"))) => gives error
(foo "y" (+ 1 (foo "x"))) => would work