Hi,
Am 22.12.12 00:37, schrieb Lee Spector:
> ;; this is defined elsewhere, and I want push-states to have fields for each
> push-type that's defined here
> (def push-types '(:exec :integer :float :code :boolean :string :zip
> :tag :auxiliary :return :environment)
>
> (defn keyword->symbol [kwd]
> "Returns the symbol obtained by removing the : from a keyword."
> (read-string (name kwd)))
I'm afraid this one is still necessary, but I would use symbol instead
of read-string.
> (defmacro define-push-state-record-type []
> "Defines the pushstate record type. The odd trick with read-string was a
> hack to
> avoid namespace qualification on the pushstate symbol."
> `(defrecord ~(read-string "pushstate") [~@(map keyword->symbol
> push-types)]))
Use ~'pushstate instead of read-string.
> (define-push-state-record-type)
>
> (defmacro make-push-state
> "Returns an empty push state."
> []
> `(pushstate. ~@(map (fn [_] nil) push-types)))
Use this:
(defn make-push-state
[]
(map->pushstate {}))
> Is there a much simpler way that I overlooked?
I'm not sure it's simpler, but it's more straight-forward, I'd say.
Kind regards
Meikel
--
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