Re: name protect anonymous macros ?
On 12/17/2010 09:54 AM, Trevor wrote: 2. Is there a form for anonymous macros? i.e. I know I can do : (fn[x](do x)), but can I not do: (macro[x](let [x# x] `(do x))) ? Thanks! A little tardy, but Konrad Hinsen has written a handful of CL-like functions for symbol macros and macrolet in clojure.contrib.macro-utils: http://clojure.github.com/clojure-contrib/macro-utils-api.html -- 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
name protect anonymous macros ?
n00b questions :) 1. How do I create a function and/or a macro that accepts an unbound name and interprets that name as a symbol? example: (defn perpetuate [name args] (do-stuff-with name args) (println name)) = (perpetuate world arg1 arg2) world this may seem silly or non-idiomatic, but really for specific functions (and more likely macros) I don't want to have to protect the name for it to be interpreted as a symbol. This is simply to accommodate my personal, good or bad, behaviors. 2. Is there a form for anonymous macros? i.e. I know I can do : (fn[x](do x)), but can I not do: (macro[x](let [x# x] `(do x))) ? Thanks! -- 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
Re: name protect anonymous macros ?
On Fri, Dec 17, 2010 at 10:54 AM, Trevor tcr1...@gmail.com wrote: n00b questions :) 1. How do I create a function and/or a macro that accepts an unbound name and interprets that name as a symbol? Function: (defn foo [x] (println x)) user=(foo 'quux) quux nil user= (defn bar [x] (do-something-with (symbol x))) user= (bar quux) ; whatever user= (defmacro baz [x y] `(def x y)) user= (baz quux 42) #'user/quux user= quux 42 this may seem silly or non-idiomatic, but really for specific functions (and more likely macros) I don't want to have to protect the name for it to be interpreted as a symbol. This is simply to accommodate my personal, good or bad, behaviors. If you mean you don't want to have to quote it, well, macro arguments aren't evaluated during macro expansion so you can generally pass unquoted symbols to macros. In fact you do so whenever you use defn. With function arguments, you need to quote a symbol to pass a symbol, or else pass a string the function will convert by using (symbol x) on it. 2. Is there a form for anonymous macros? Nope. I'm not sure why you'd want one, either. -- 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
Re: name protect anonymous macros ?
Thanks for responding, but I know all this. 1. I know how to pass string and symbols into functions and I know how to coerce. 2. I don't want to bind the name, I want to interpret the name as a symbol, thus - (defmacro baz [x y] `(def x y)), is not useful. 3. CL has anonymous macros, so why do you think CL has them - because they're not useful? On Dec 17, 9:31 am, Ken Wesson kwess...@gmail.com wrote: On Fri, Dec 17, 2010 at 10:54 AM, Trevor tcr1...@gmail.com wrote: n00b questions :) 1. How do I create a function and/or a macro that accepts an unbound name and interprets that name as a symbol? Function: (defn foo [x] (println x)) user=(foo 'quux) quux nil user= (defn bar [x] (do-something-with (symbol x))) user= (bar quux) ; whatever user= (defmacro baz [x y] `(def x y)) user= (baz quux 42) #'user/quux user= quux 42 this may seem silly or non-idiomatic, but really for specific functions (and more likely macros) I don't want to have to protect the name for it to be interpreted as a symbol. This is simply to accommodate my personal, good or bad, behaviors. If you mean you don't want to have to quote it, well, macro arguments aren't evaluated during macro expansion so you can generally pass unquoted symbols to macros. In fact you do so whenever you use defn. With function arguments, you need to quote a symbol to pass a symbol, or else pass a string the function will convert by using (symbol x) on it. 2. Is there a form for anonymous macros? Nope. I'm not sure why you'd want one, either. -- 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
Re: name protect anonymous macros ?
On Fri, Dec 17, 2010 at 1:22 PM, Trevor tcr1...@gmail.com wrote: Thanks for responding, but I know all this. 1. I know how to pass string and symbols into functions and I know how to coerce. 2. I don't want to bind the name, I want to interpret the name as a symbol In what sense? Apparently (symbol the-name) doesn't suffice for your purposes. I think we need to know what those purposes actually are, in much more detail. 3. CL has anonymous macros, so why do you think CL has them - because they're not useful? I didn't claim they weren't useful. I said, and I quote, I'm not sure why you'd want one. That's not quite the same thing, because it allows for the possibility that there is a good use for them that has thus far escaped my notice. If you know of such a use, by all means describe it here. -- 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
Re: name protect anonymous macros ?
On Dec 17, 8:31 am, Ken Wesson kwess...@gmail.com wrote: 2. Is there a form for anonymous macros? Nope. I'm not sure why you'd want one, either. This was my reaction too, but after some thought I can imagine scenarios where it would be useful. For example, say I want to defn several versions of the same function, with slightly different options: (defn quiet-foo [x] (magic x :quiet)) (defn loud-foo [x] (magic x :loud)) I could write a macro to do this, then call the macro N times for my N functions: (defmacro make-foo [name opt] `(defn ~name [x#] (magic x# ~opt))) (make-foo quiet-foo :quiet) But it might be nice to have some syntax like: ((macro [ name-opts] (doseq [[name opt] (partition 2 name-opts)] `(defn ~name [x#] (magic x# ~opt [quiet-foo :quiet, loud-foo :loud]) -- 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
Re: name protect anonymous macros ?
On Fri, Dec 17, 2010 at 1:37 PM, Alan a...@malloys.org wrote: On Dec 17, 8:31 am, Ken Wesson kwess...@gmail.com wrote: 2. Is there a form for anonymous macros? Nope. I'm not sure why you'd want one, either. This was my reaction too, but after some thought I can imagine scenarios where it would be useful. For example, say I want to defn several versions of the same function, with slightly different options: (defn quiet-foo [x] (magic x :quiet)) (defn loud-foo [x] (magic x :loud)) I could write a macro to do this, then call the macro N times for my N functions: (defmacro make-foo [name opt] `(defn ~name [x#] (magic x# ~opt))) (make-foo quiet-foo :quiet) But it might be nice to have some syntax like: ((macro [ name-opts] (doseq [[name opt] (partition 2 name-opts)] `(defn ~name [x#] (magic x# ~opt [quiet-foo :quiet, loud-foo :loud]) Yeah, perhaps, though for your toy example there's more lines of code with either macro than without any macros. Of course you might also want to abstract out the fact that quiet and loud get repeated in the names. Say, (defmacro make-foo [opt] (let [name (symbol (str opt -foo)) opt-kw (keyword (str opt))] `(defn ~name [x#] (magic x# ~opt-kw user= (macroexpand-1 '(make-foo quiet)) (clojure.core/defn quiet-foo [x__1387__auto__] (user/magic x__1387__auto__ :quiet)) (= (defn quiet-foo [x] (magic x :quiet))) You don't even have to stick a ' or a : before the word quiet, or around it -- just (make-foo quiet)! -- 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
Re: name protect anonymous macros ?
2. I don't want to bind the name, I want to interpret the name as a symbol user= (defmacro perpetuate [name] `(let [q# (quote ~name)] (println q#) q#)) #'user/perpetuate user= (class (perpetuate somename)) somename clojure.lang.Symbol -- 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
Re: name protect anonymous macros ?
ahhh - thank you! On Dec 17, 1:23 pm, Armando Blancas armando_blan...@yahoo.com wrote: 2. I don't want to bind the name, I want to interpret the name as a symbol user= (defmacro perpetuate [name] `(let [q# (quote ~name)] (println q#) q#)) #'user/perpetuate user= (class (perpetuate somename)) somename clojure.lang.Symbol -- 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
Re: name protect anonymous macros ?
On Fri, Dec 17, 2010 at 3:26 PM, Trevor tcr1...@gmail.com wrote: ahhh - thank you! On Dec 17, 1:23 pm, Armando Blancas armando_blan...@yahoo.com wrote: 2. I don't want to bind the name, I want to interpret the name as a symbol user= (defmacro perpetuate [name] `(let [q# (quote ~name)] (println q#) q#)) #'user/perpetuate user= (class (perpetuate somename)) somename clojure.lang.Symbol Is *that* all you wanted? A version of (quote x) that printed out its argument as well as evaluating to a symbol? Well why didn't you just *say* so? -- 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
Re: name protect anonymous macros ?
Lol.You're correct - it's so easy i don't know why I didn't see it. I'm somewhat new to macros. That said - I thought my question was clearly stated: How do I create a function and/or a macro that accepts an unbound name and interprets that name as a symbol? On Dec 17, 1:35 pm, Ken Wesson kwess...@gmail.com wrote: On Fri, Dec 17, 2010 at 3:26 PM, Trevor tcr1...@gmail.com wrote: ahhh - thank you! On Dec 17, 1:23 pm, Armando Blancas armando_blan...@yahoo.com wrote: 2. I don't want to bind the name, I want to interpret the name as a symbol user= (defmacro perpetuate [name] `(let [q# (quote ~name)] (println q#) q#)) #'user/perpetuate user= (class (perpetuate somename)) somename clojure.lang.Symbol Is *that* all you wanted? A version of (quote x) that printed out its argument as well as evaluating to a symbol? Well why didn't you just *say* so? -- 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