Hi Anders,

(defmacro def-name [name-vec & body]
  `(let ~(vec (interleave (map symbol name-vec)
                          name-vec))
       ~@body))

user=> (macroexpand '(def-name ["a" "b" "c"] 1 2 3))
(let* [a "a" b "b" c "c"] 1 2 3)

user=> (def-name ["a" "b" "c"] a)
"a"
user=> (def-name ["a" "b" "c"] b)
"b"
user=> (def-name ["a" "b" "c"] (str a b))
"ab"

Best,
Alex

On Tue, Jul 23, 2013 at 12:18 AM, <eliassona...@yahoo.com> wrote:

> Hi,
> I want to write a macro that introduces new variables from data.
> The data is a vector and looks like this for example: ["a" "b" "c"]
>
> I want to use the macro like this:
> (def-names ["a" "b" "c"] (str a b))
>
> What code I want the macro to produce from the above is the following:
> (let [a "a"
>        b "b"
>        c "c"]
>   (str a b))
>
> Is it possible to do that?
> Is it a good thing to do that or is it bad practice?
>
> Thanks
> --anders
>
>
>
> --
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to