Hi, Laurent, Your suggestion of manually piping intermediate results works. Thank you very much!
Tuba On Thu, Jul 28, 2011 at 3:44 AM, Laurent PETIT <laurent.pe...@gmail.com>wrote: > Hi, > > 2011/7/28 Tuba Lambanog <tuba.lamba...@gmail.com> > >> Hello, >> >> I'm trying to pass a variable through a series of functions, which may >> change the value of the variable. However, the next function in line >> uses the original value, rather than the changed value. Here's a >> pseudo-code of what I'm doing. >> >> (defn process-1 [s] >> ; change value of s then return it >> s) >> >> (def s "something") >> (do >> (process-1 s) ; variable s is changed here >> (process-2 s)) ; process-2 uses the original value of s, not the >> return value from process-1 >> >> > beware, "change" in the clojure world means "computing a new value based on > an old one" (as opposed to creating a new value "almost from scratch"). > > So for example, when you add an element to a map : > (def m1 {:a 1}) > (def m2 (assoc m1 :b 2)) > > you're really creating a new value. > People will sometimes say they "change" m1, but it's not true, it's more to > say that m2 is derived from m1 (sharing most things with m1). > > So you need to "pipe" the return value of process-1 into process-2. > > The "manual way" to do the pipe : > (let [s-p1 (process-1 s) > s-p2 (process-2 s-p1)] > s-p2) > > The "short" way (preferred in your case) : > (-> s process-1 process-2) > > HTH, > > -- > Laurent > > >> Thanks for the help. >> >> Perhaps a sub-forum for beginners? Kind of embarrassing to ask here >> questions that are so newbie-ish. >> >> -- >> 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