Re: confusing macro issue: java.lang.InstantiationException

2012-01-21 Thread Cedric Greevey
On Sat, Jan 21, 2012 at 2:47 AM, drewn wrote: > Thank you, that works great!  It's a nice use of destructuring too, > which I should of thought of. ... > Thanks for a great lesson on macros! You're welcome. :) -- You received this message because you are subscribed to the Google Groups "Cloju

Re: confusing macro issue: java.lang.InstantiationException

2012-01-20 Thread drewn
Thank you, that works great! It's a nice use of destructuring too, which I should of thought of. I guess this is one case where solving the problem in pieces does not help. Actually, I seem to remember seeing idioms like that for other macros over sequences. I understand a little more now why.

Re: confusing macro issue: java.lang.InstantiationException

2012-01-20 Thread Cedric Greevey
On Fri, Jan 20, 2012 at 9:54 PM, drewn wrote: > I've been trying to write a macro to generate predicates from maps, > for instance the map {1 :one 2 :two} would define two predicates, one? > and two? What's the use case for this? (def one? #{1}) (def two? #{2}) isn't much worse. I suppose a mac

confusing macro issue: java.lang.InstantiationException

2012-01-20 Thread drewn
I've been trying to write a macro to generate predicates from maps, for instance the map {1 :one 2 :two} would define two predicates, one? and two? Here's the first part of the macro: (defmacro make-predicate [keyword-pair] `(defn ~(symbol (str (name (nth (eval keyword-pair) 1)) "?")) [~'x]

Re: macro issue

2009-05-20 Thread Per
Thanks, that makes a lot of sense! Per On May 20, 10:36 am, Chouser wrote: > On Wed, May 20, 2009 at 9:59 AM, Michael Reid wrote: > > > On Wed, May 20, 2009 at 8:44 AM, pmf wrote: > > >> On May 20, 4:47 am, Per wrote: > >>> ;; The macro > >>> (defmacro def-fields [name  tgs] > >>>   `(defs

Re: macro issue

2009-05-20 Thread Per
Thanks, this is going in the right direction. The macro expansion looks correct, but the actual execution still fails: user=> (macroexpand '(def-fields fs tags)) (def fs (clojure.core/create-struct :name :age)) user=> (def-fields fs tags) java.lang.Exception: Unable to resolve symbol: :name i

Re: macro issue

2009-05-20 Thread Chouser
On Wed, May 20, 2009 at 9:59 AM, Michael Reid wrote: > > On Wed, May 20, 2009 at 8:44 AM, pmf wrote: >> >> On May 20, 4:47 am, Per wrote: >>> ;; The macro >>> (defmacro def-fields [name  tgs] >>>   `(defstruct ~name ~@(map #(symbol (str ":" %)) tgs)) >>> ) >> >> If you replace the call to 'symb

Re: macro issue

2009-05-20 Thread Michael Reid
On Wed, May 20, 2009 at 8:44 AM, pmf wrote: > > On May 20, 4:47 am, Per wrote: >> ;; The macro >> (defmacro def-fields [name tgs] >> `(defstruct ~name ~@(map #(symbol (str ":" %)) tgs)) >> ) > > If you replace the call to 'symbol' with a call to 'keyword', it works > (I think this is what you

Re: macro issue

2009-05-20 Thread pmf
On May 20, 4:47 am, Per wrote: > ;; The macro > (defmacro def-fields [name  tgs] >   `(defstruct ~name ~@(map #(symbol (str ":" %)) tgs)) > ) If you replace the call to 'symbol' with a call to 'keyword', it works (I think this is what you intended). --~--~-~--~~~---~-

macro issue

2009-05-20 Thread Per
I want to write a macro that runs a 'defstruct' using a list of names, like below: ;; My tag names (def tags '("name" "age")) ;; The macro (defmacro def-fields [name tgs] `(defstruct ~name ~@(map #(symbol (str ":" %)) tgs)) ) ;; Using the macro to define a struct based on 'tags' (def-fields