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]
  `(let [~bvec ~val]
     (-> {}
         ~@(for [s (remove #(= '& %) (flatten bvec))]
             `(assoc (-> (quote ~s) name keyword) ~s)))))

Example:

(let [v [1 2 [3 4 5 6 7 8]]]
  (destructure->map [a b [c d & e]] v))
=> {:e (5 6 7 8), :d 4, :c 3, :b 2, :a 1}


Justin

On Feb 7, 10:49 am, CuppoJava <patrickli_2...@hotmail.com> wrote:
> 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]}
>
> ------------------------------------------------------------
>
> Now this is not too difficult of a function to write from scratch. BUT
> it really looks like I should be able to piggy-back off the existing
> functionality in the destructuring-let macro. But I cannot figure out
> how I can do that without using eval. I'm not sure if it's even
> possible.
>
> Does anyone know if it's possible to implement this function in terms
> of "let" and without using "eval"? Thank you very much for your help!
>   -Patrick

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