On Mon, Jan 9, 2012 at 10:36 AM, Linus Ericsson
<oscarlinuserics...@gmail.com> wrote:
> I want to generate rules with constant and/or functions producing parts of
> the rules:
>
> (defn rulemaker []
>    (str "SCOPE " global-constant ";" (some-global-function) ";"))
>
> which could be called with
>
> (with-super-closure model-in-file-reference
>     (rulemaker))
>
> Is there a way to make some "temporary global constants" that could be
> reached from a function without passing it the this state or closure
> explicitly?
>
> What's the simpler way? Should I simply make a search-replace table which I
> prepare and run all the templates through or is there another way? I would
> love to be able not to pass around a state, like
>
> (defn rulemaker [z] (str "SCOPE " (some-generator-function z)))
>
> since that's a bit error-prone and verbose. Is this one of few occasions for
> a macro or should I somehow create a namespace or something explicitly for
> this code-generation? All magic allowed, since it's a very restricted domain
> that rather should be as convenient as possible to use.

Dynamic binding is often used for this sort of purpose. It has
caveats, though, particularly when the binding is used in generating a
lazy seq. If the seq is passed out of the binding's scope while still
at least partly unrealized, attempting to realize the remaining
elements may not go as planned.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to