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
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.
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
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]
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
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
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
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
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).
--~--~-~--~~~---~-
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
10 matches
Mail list logo