Hi!

Defining an entity with appengine-magic is straightforward:
----
(ns tlog.models
  (:require [appengine-magic.services.datastore :as ds]))

(ds/defentity Article [^:key slug, title, body, created-t, updated-t])
----

But there are several places (other files), where that list sans the first element would be handy and I would like to avoid copy-pasting [title, body, created-t, updated-t].

ds/defentity is a macro and won't work if it sees functions at compile time (I hope this way to put it is acceptable, but tell me if my mental model is lacking).

amaloy helped me with an almost-solution. The following works:
----
(defmacro def-entity-and-attrs [entity-name key attrs]
  `(ds/defentity ~entity-name ~(vec (concat ['^:key key] attrs))))

(def-entity-and-attrs Article slug [title, body, created-t, updated-t])
----

But it was meant to be:
----
(defmacro def-entity-and-attrs [entity-name key attrs-name attrs]
  `(do (def ~attrs-name ~attrs)
       (ds/defentity ~entity-name ~(vec (concat ['^:key key] attrs)))))

(def-entity-and-attrs Article slug
  attrs-name [title, body, created-t, updated-t])
----
Fails with: "Unable to resolve symbol: title in this context"
Or if I quote the vector: "clojure.lang.PersistentVector cannot be cast to clojure.lang.Symbol"

I guess trying to access attrs-name from elsewhere would have been "fun", anyway.

I would love to simply
----
(def article-attrs '[title, body, created-t, updated-t])
----
and work with that.

It's not the first time I run into a situation where things beg to be composited/concatenated, but can't be, at least not easily.

Any ideas?

--
Thorsten Wilms

thorwil's design for free software:
http://thorwil.wordpress.com/

--
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

Reply via email to