Re: Help writing a simple destructuring function.

2011-02-07 Thread Ken Wesson
On Tue, Feb 8, 2011 at 12:31 AM, CuppoJava wrote: > Thanks for the reply Ken. > > "While the macro is executing "body" will be bound to an > s-expression (basically, source code parsed to an AST but no further; > source code as processed by the reader). " > > This is the part where it falls apart.

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
Thanks for the reply Ken. "While the macro is executing "body" will be bound to an s-expression (basically, source code parsed to an AST but no further; source code as processed by the reader). " This is the part where it falls apart. "body" is actually bound to a single symbol. For example in t

Re: Help writing a simple destructuring function.

2011-02-07 Thread Ken Wesson
On Mon, Feb 7, 2011 at 10:06 PM, CuppoJava wrote: > I've thought about that actually. And it wouldn't work. > > So (defn destructure [form value] >       ...magic...) > > (defmacro let [forms body] >  `(let* ~(vec (destructure forms body))  <- at this point, "body" is > not known yet. It's just a

Re: Help writing a simple destructuring function.

2011-02-07 Thread David Nolen
On Mon, Feb 7, 2011 at 10:06 PM, CuppoJava wrote: > I've thought about that actually. And it wouldn't work. > > So (defn destructure [form value] >...magic...) > > (defmacro let [forms body] > `(let* ~(vec (destructure forms body)) <- at this point, "body" is > not known yet. It's just

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
I've thought about that actually. And it wouldn't work. So (defn destructure [form value] ...magic...) (defmacro let [forms body] `(let* ~(vec (destructure forms body)) <- at this point, "body" is not known yet. It's just a symbol. ~@body) This approach won't work because "body" i

Re: Help writing a simple destructuring function.

2011-02-07 Thread Alan
(defn destructure [binding-form] ...magic...) (defmacro let [forms body] `(let* ~(vec (destructure forms)) ~@body)) On Feb 7, 1:46 pm, CuppoJava wrote: > Actually that would be fine as a solution as well. I'm stumped as to > how to avoid repeating the same thing twice (once in function

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
Actually that would be fine as a solution as well. I'm stumped as to how to avoid repeating the same thing twice (once in function world and once in macro world). ie. Let's assume that we have this destructuring function. How do we use that do program a destructuring let macro? -Patrick On Feb

Re: Help writing a simple destructuring function.

2011-02-07 Thread Ken Wesson
On Mon, Feb 7, 2011 at 3:01 PM, Meikel Brandmeyer wrote: > Hi, > > Am 07.02.2011 um 20:51 schrieb CuppoJava: > >> Thanks for your answer Meikel. >> >> Your answer isn't that ugly. It's very similar to what I have as >> well. >> >> I would like to know if you think it's possible to re-use "let" to

Re: Help writing a simple destructuring function.

2011-02-07 Thread Meikel Brandmeyer
Hi, Am 07.02.2011 um 20:51 schrieb CuppoJava: > Thanks for your answer Meikel. > > Your answer isn't that ugly. It's very similar to what I have as > well. > > I would like to know if you think it's possible to re-use "let" to do > this. I feel like I'm re-inventing the wheel somewhat. I don't

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
Thanks for your answer Meikel. Your answer isn't that ugly. It's very similar to what I have as well. I would like to know if you think it's possible to re-use "let" to do this. I feel like I'm re-inventing the wheel somewhat. -Patrick On Feb 7, 2:44 pm, Meikel Brandmeyer wrote: > Hi, > > Am

Re: Help writing a simple destructuring function.

2011-02-07 Thread Meikel Brandmeyer
Hi, Am 07.02.2011 um 20:26 schrieb CuppoJava: > I was wondering whether the "destructure" function can be written > using the existing "let" form. Thanks for your help. Ah ok. Nevermind. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" g

Re: Help writing a simple destructuring function.

2011-02-07 Thread Meikel Brandmeyer
Hi, Am 07.02.2011 um 18:20 schrieb Justin Kramer: > Checking out clojure.core/destructure and clojure.core/let might be > helpful. > > Here's a macro I hacked together. It doesn't work with :keys, :as, > or :or. I take no responsibility if you use it for anything real. But > maybe it will provid

Re: Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
Sorry, I wasn't being very clear about my needs. I need this function to run at *run-time*. So the following: (def values [1 2 [3 4 5 6 7 8]]) (def form '(a b (c d & e))) (destructure form values) Should return: {:a 1 :b 2 :c 3 :d 4 :e [5 6 7 8]} I was wondering whether the "destructure" functi

Re: Help writing a simple destructuring function.

2011-02-07 Thread Fogus
I have a library called Evalive (http://github.com/fogus/evalive) that could help. Specifically I added a macro named `destro` that will do _mostly_ what you want. Basically, it looks like the following: (destro [a b [c d & e]] [1 2 [3 4 5 6 7 8]]) Which returns: {vec__2183 [1 2 [3 4 5 6 7 8]

Re: Help writing a simple destructuring function.

2011-02-07 Thread Justin Kramer
Checking out clojure.core/destructure and clojure.core/let might be helpful. Here's a macro I hacked together. It doesn't work with :keys, :as, or :or. I take no responsibility if you use it for anything real. But maybe it will provide you with some ideas. (defmacro destructure->map [bvec val]

Help writing a simple destructuring function.

2011-02-07 Thread CuppoJava
Hello everyone, I am trying to write the following function: --- Suppose form = [1 2 [3 4 5 6 7 8]] (destructure '(a b (c d & e)) form) should return: {:a 1 :b 2 :c 3 :d 4 :e [5 6 7 8]} -