Reference passing question

Q&A's, tips, howto's
Locked
Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Reference passing question

Post 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?
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post 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?
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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 :-((

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

That's great. That is something that I really needed.
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Locked