Hi Meikel,

That's what I original thought I might have to do. But it seemed
overly complicated. Perhaps there's no way around it.

I have a small question about the "with-bindings" function that you
used.

That one establishes dynamically scoped variables. Can't there be
another Clojure function that provides lexically scoped variables?

I actually don't know of any lisp/scheme system that provides a way to
introduce lexically scoped variables at runtime. Do you know if
there's a fundamental reason against doing so?

  -Patrick

On Feb 10, 9:27 am, Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi,
>
> On 10 Feb., 14:58, CuppoJava <patrickli_2...@hotmail.com> wrote:
>
> > That's an awesome solution Meikel!
>
> You are welcome. :)
>
> > I forgot to specify that I want the bindings to have lexical scope
> > only. But I think I can get that to work easily by modifying your
> > solution.
>
> Haha. In fact that was my first impulse. But then I saw the (def a)
> and read "bind" and changed my interpretation to dynamic scope.
>
> Lexical scope is much harder. The only "simple" solution, I see at the
> moment, is walking the body of bind-later and do substitution. This is
> in general ugly, but the only thing I can think of at the moment. This
> is a (very) rough sketch, but you should get the key idea.
>
> (declare do-bind)
>
> (defn magic-walk-fn
>   [form locals db env]
>   (if (seq? form)
>     (let [[f & args] form
>           args       (map magic-walk-fn args)]
>       (if (when-not (contains? env f)
>             (= #'do-bind (resolve f)))
>         `((fn [~locals] ~@args) ~db)
>         `(~f ~@args)))
>     (else-do-other-walking-magic form)))
>
> (defmacro bind-later
>   [bindings & body]
>   (let [db     (gensym "deferred-bindings")
>         locals (vec (take-nth 2 bindings))
>         values (vec (take-nth 2 (next bindings)))]
>     `(let [~db ~values]
>        ~@(map #(magic-walk-fn % locals db &env) body))))
>
> Note that do-bind is just a dummy to identify the correct forms to
> transform.
>
> Sincerely
> Meikel

-- 
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