When applying a function defined in a context to a table defined outside of that context, how can you do assoc lookups? For example:
(context 'foo)
(define (some-fn table)
(lookup 'key-a table))
(context 'bar)
(some-fn '((key-a "value-a") (key-b "value-b")))
some-fn may be used from various contexts. In order to lookup key-a, it must know which context we are coming from. I can do a (name table true), but then to get the correct symbol to look up, I'm forced to do something like:
(eval-string (format "%s:key-a" (string (name table true)))
...which is incredibly verbose syntax just for a table lookup. Anyone have a solution?
Never mind. I've figured it out.
If I create the list in question inside of a context, and then I can pass the context to the function in another context. With the example above:
(context 'foo)
(define (some-fn ctx)
(lookup 'ctx:key-a ctx:table))
(context 'bar)
(set 'table ((key-a "value-a") (key-b "value-b")))
(context 'whatever)
(foo:some-fn bar)
Now, foo is reading the context of the input, and can lookup based on the context's symbols in the context's lists.
... and as an added benefit you have passed your bar:table by reference, which is nice if your are dealing with a lot of data.
Lutz
I always prefer to do lots of work at the bar:table. Preferably with a glass:full ;)
Quote from: "Jeff"
I always prefer to do lots of work at the bar:table. Preferably with a glass:full ;)
[Click here for audio response.] (//http) :-)