On Wed, Aug 27, 2008 at 4:39 AM, Parth Malwankar
<[EMAIL PROTECTED]> wrote:
> After some more experimentation I found that the field-write
> macro didn't work with access-specs like (vector :a :b :c)
> ... I should have thought of that before.
>
> So I reimplemented field-read and field-write as functions
> which seem to work in all scenarios.
>
> (defn field-read [st as]
>  "user=> nx
>  {:a {:b {:c {:data 10}}}}
>  user=> (field-read nx [:a :b :c])
>  {:data 10}"
>  (eval (reduce (comp reverse list) st as)))

> I suspect using eval in field-read is a bad idea (preformance?) but I
> couldn't come up with a better way to do it. access-spec
> needs to be a vector as its something thats returned by
> another function in my use case (otherwise I could have
> used it with ->).

No need for eval here:

(defn field-read [st as]
  (loop [st st as as]
    (if (first as)
      (recur (get st (first as))
             (rest as))
      st)))

Best,
Graham

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to