You are correct. The struct is a single message. The messages object holds a ref to N of them (initially an empty vector).
Individual messages are added by alter ... conj in add-message. Stu > > Ok, then I understand why it didn't work, but that means that the > struct (that is sent by the add-message function) is put in a sequence > somewhere on the way to being validated. Is this right, and where does > this happen? > > > ;All the relevant code > > (defstruct message :sender :text) > > (def validate-message-list > (partial every? #(and (:sender %) (:text %)))) > > (def messages (ref [] :validator validate-message-list)) > > (defn add-message [msg] > (dosync (alter messages conj msg))) > > (add-message (struct message "mm" "first message")) > > > > > > On Jun 23, 12:58 pm, Stuart Halloway <stuart.hallo...@gmail.com> > wrote: >> Hi Michele, >> >> Pass a sequence of maps, not just a map: >> >> (every? #(:x %) [{:x "s"}]) >> -> true >> >> Cheers, >> Stu >> >> >> >>> In the book "Programming Clojure" (p2_0, pdf, page 185) "Adding >>> Validation to Refs" there is this code: >> >>> (def validate-message-list (partial every? #(and (:sender %) (:text >>> %)))) >> >>> This works fine as a validator, but when I try the code directly - not >>> as a validator - it returns false. I also tested with a simple "if" to >>> see the difference. >> >>> (every? #(:x %) {:x "s"}) >>> -> false >> >>> (if (#(:x %) {:x "s"}) "TRUE" "FALSE") >>> -> "TRUE" >> >>> What do I not understand? >> >>> -- >>> 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 > > -- > 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 -- 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