You're correct. They both do the same thing. Both do not update mtr- map. Clearly I need to assign a local variable in a let statement.
(mtr-map passed as parameter version) (def mtr-seq ["a" 1 "b" 2 "c" 3 "d" 4]) (defn map-mtr [read-map premid reading] (conj read-map {premid reading})) (map-mtr mtr-map (first mtr-seq) (first (rest mtr-seq))) {"a" 1} mtr-map {} (version with def mtr-map) (defn map-mtr [premid reading] (conj mtr-map {premid reading})) #'user/map-mtr user=> (map-mtr (first mtr-seq) (first (rest mtr-seq))) {"a" 1} user=> mtr-map {} On Jun 30, 12:05 pm, Mark Rathwell <mark.rathw...@gmail.com> wrote: > It shouldn't. I can't duplicate what I think you are saying. Would you be > able to you print the code you entered in the repl that produced these > results? > > On Thu, Jun 30, 2011 at 12:02 PM, octopusgrabbus > <octopusgrab...@gmail.com>wrote: > > > > > > > > > Thanks you for answering. > > > I should rephrase the question, and I'll go look at the links you > > posted. > > > I'm wondering why conj worked in the first of the function that > > operated on the mtr-map defined by def, and not in the version where > > mtr-map was passed in as the first parameter. > > > On Jun 30, 11:48 am, Mark Rathwell <mark.rathw...@gmail.com> wrote: > > > Clojure data structures are immutable by default (seehttp:// > > clojure.org/functional_programming). > > > > For mutability, see the following: > > > >http://clojure.org/vars > > > <http://clojure.org/vars>http://clojure.org/atoms > > > >http://clojure.org/refs > > > >http://clojure.org/agents > > > >http://clojure.org/transients > > > > On Thu, Jun 30, 2011 at 11:35 AM, octopusgrabbus > > > <octopusgrab...@gmail.com>wrote: > > > > > Given this empty map, > > > > > (def mtr-map {}) > > > > > this sequence, > > > > > (def mtr-seq ["a" 1 "b" 2 "c" 3 "d" 4]) > > > > > this function, > > > > > (defn map-mtr > > > > [read-map premid reading] > > > > (conj read-map {premid reading})) > > > > > and this call > > > > > (map-mtr mtr-map (first mtr-seq) (first (rest mtr-seq))) > > > > > mtr-map won't update, but redefining the function to take premid and > > > > reading and allowing the function to operate on the global variable > > > > mtr-map. > > > > > (defn map-mtr > > > > [premid reading] > > > > (conj mtr-map {premid reading})) > > > > > mtr-map becomes updated. > > > > > I'm confused as to how to update mtr-map by allowing it to be passed > > > > into the function in the first example. > > > > > -- > > > > 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