I use a similar macro in my music
code<https://github.com/ctford/leipzig/blob/master/src/leipzig/scale.clj>,
because I want to take a sequence and explicitly give parts of it names.
(defmacro defs [names docstring values]
`(do ~@(map
(fn [name value] `(def ~name ~docstring ~value))
names (eval values))))
(defs
[C D E F G A B]
"A key, expressed as a translation function."
(map
(comp from (from 60) major)
(range)))
This macro is not part of the public API. :-)
On 23 July 2013 10:52, Alex Baranosky <[email protected]> wrote:
> Good point BG,
>
> I think it is almost certainly not a good idea :) But educational,
> definitely.
>
>
> On Tue, Jul 23, 2013 at 12:48 AM, Baishampayan Ghose <[email protected]>wrote:
>
>> Since the bindings are a function of the data that's passed in, IMO
>> you don't need a anaphoric macro for this.
>>
>> For example -
>>
>> (defmacro def-names [names & body]
>> (let [bindings* (vec (mapcat (juxt symbol identity) names))]
>> `(let ~bindings*
>> ~@body)))
>>
>> As to whether it's a good idea or not, I'd say it depends but YMMV.
>>
>> Regards,
>> BG
>>
>> On Tue, Jul 23, 2013 at 12:48 PM, <[email protected]> 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 [email protected]
>> > Note that posts from new members are moderated - please be patient with
>> your
>> > first post.
>> > To unsubscribe from this group, send email to
>> > [email protected]
>> > 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 [email protected].
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>>
>>
>>
>> --
>> Baishampayan Ghose
>> b.ghose at gmail.com
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> 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 [email protected].
>> 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 [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.