Re: Tricky Macro to write.

2011-02-11 Thread Ken Wesson
On Fri, Feb 11, 2011 at 10:59 AM, CuppoJava wrote: > I realized, actually, after your post Ken, that my implementation of > macroexpand-all does not do exactly what I want. > > The properties of macroexpand-all, should be: > > (eval some-expression) is *always* equal to (eval (macroexpand-all > so

Re: Tricky Macro to write.

2011-02-11 Thread CuppoJava
I realized, actually, after your post Ken, that my implementation of macroexpand-all does not do exactly what I want. The properties of macroexpand-all, should be: (eval some-expression) is *always* equal to (eval (macroexpand-all some-expression)) This is not the case in my current implementati

Re: Tricky Macro to write.

2011-02-10 Thread Ken Wesson
On Thu, Feb 10, 2011 at 11:10 PM, CuppoJava wrote: > Your solution with map-ps is quite elegant. Thanks. My implementation of macrolet also uses it. In fact, I wrote my macroexpand-all as a tool to aid in developing that. It was useful both for debugging macrolet itself and for testing which "spe

Re: Tricky Macro to write.

2011-02-10 Thread CuppoJava
Your solution with map-ps is quite elegant. I was actually a little annoyed that I had to deal with different data structures when walking through Clojure code, as opposed to Lisp/Scheme code. The doall was necessary for my use-case actually. Some of the macros I write interact with the environmen

Re: Tricky Macro to write.

2011-02-10 Thread Ken Wesson
On Thu, Feb 10, 2011 at 11:01 AM, CuppoJava wrote: > Thanks for all your help everyone! > > So I came up with an elegant solution. It was a combination of > Meikel's codwalker solution gave me the idea to bootstrap off of > Clojure's macroexpand system to get it to work. > > ;;This is a convenienc

Re: Tricky Macro to write.

2011-02-10 Thread Alan
See the clojure.walk namespace. It has macroexpand-all and walk/ prewalk functions which would make this much simpler. That said: yes, of course there is a form that introduces lexical bindings; it's called let (as shown in Mike Meyers's solution). On Feb 10, 8:01 am, CuppoJava wrote: > Thanks f

Re: Tricky Macro to write.

2011-02-10 Thread CuppoJava
Thanks for all your help everyone! So I came up with an elegant solution. It was a combination of Meikel's codwalker solution gave me the idea to bootstrap off of Clojure's macroexpand system to get it to work. ;;This is a convenience method for expanding macros. It recursively ;;macroexpands eve

Re: Tricky Macro to write.

2011-02-10 Thread Mike Meyer
On Wed, 9 Feb 2011 20:34:56 -0800 (PST) CuppoJava wrote: > Description: (bind-later bindings & body) and (do-binding & body) > (bind-later) is used like a let-form, except that it doesn't > *immediately* make the bindings available. > The bindings become available only within (do-binding). > (do

Re: Tricky Macro to write.

2011-02-10 Thread Meikel Brandmeyer
Hi, On 10 Feb., 15:54, CuppoJava wrote: > 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 ru

Re: Tricky Macro to write.

2011-02-10 Thread CuppoJava
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 t

Re: Tricky Macro to write.

2011-02-10 Thread Meikel Brandmeyer
Hi, On 10 Feb., 14:58, CuppoJava 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 the

Re: Tricky Macro to write.

2011-02-10 Thread CuppoJava
That's an awesome solution Meikel! 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. Thanks! -Patrick On Feb 10, 2:09 am, Meikel Brandmeyer wrote: > Whoops. Misclick. Sorry > > Here again: > > (def *d

Re: Tricky Macro to write.

2011-02-09 Thread Meikel Brandmeyer
Whoops. Misclick. Sorry Here again: (def *deferred-bindings* {}) (defmacro do-binding [& body] `(with-bindings *deferred-bindings* ~@body)) (defmacro bind-later [bindings & body] (let [vars (map (fn [v] `(var ~v)) (take-nth 2 bindings)) values (take-nth 2 (next bindings))

Re: Tricky Macro to write.

2011-02-09 Thread Meikel Brandmeyer
Hi, here my try: (def *deferred-bindings* {}) (defmacro do-binding [& body] `(with-bindings *deferred-bindings* ~@body)) (defmacro bind-later [bindings & body] (let [vars (map (fn [v] `(var ~v)) (take-nth 2 bindings)) values (take-nth 2 (next bindings))] `(binding [*d