On Sun, 7 Mar 2010 12:35:27 +0800 Mike Mazur <mma...@gmail.com> wrote:
> Hi, > > On Sat, Mar 6, 2010 at 20:36, Manfred Lotz <manfred.l...@arcor.de> > wrote: > > Now I tried a different way: > > > > (defstruct st :a :b) > > > > (defn my-struct-map [s & inits] > > (let [sm (struct-map s inits)] > > (if (= nil (sm :b)) > > (assoc sm :b 0.0) > > sm)) > > ) > > > > Unfortunately, the part sm (struct-map s inits) doesn't work. I > > have no idea what is wrong with my code. > > The problem is with the inits argument passed to struct-map. Your > method will pass a sequence. For instance, if you invoke > (my-struct-map st :a 1 :b 2), struct-map is invoked like this: > (struct-map st (:a 1 :b 2)). > Oh yes, I was not aware of this, although it is pretty logical. > I didn't know how to fix this myself, but nteon on the IRC helped out > and pointed me to apply. So, this definition now works for me: > > (defn my-struct-map [s & inits] > (let [sm (apply struct-map s inits)] > (if (= nil (sm :b)) > (assoc sm :b 0.0) > sm))) > Yep, helped. -- Thanks, Manfred -- 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