Basically, when I'm solving the problem, I'd think "average is sum of the items divided by the count".
So... (defn average [coll] (/ (sum coll) (count coll))) Then, "since count is defined, I just need to define sum". (defn sum [coll] (reduce + coll)) In that order: 1 2 Without declare, I write 2 1 Even with declare, best case, I'm still bouncing like this: 2 1 3 It just seems to interrupt my flow when coding. Maybe that's not a legitimate enough concern, but coming from first principles, that seems to be one of the fundamental gains of Clojure. On Feb 22, 6:40 pm, Daniel Bell <dchristianb...@gmail.com> wrote: > This is true. But you "declare" lets you throw out all the names you > need to at the beginning to avoid circular definitions and the like. > > eg. > (declare sum) > > (defn average [coll] > (/ (sum coll) (count coll))) > > (defn sum [coll] > (apply + coll)) > > On Feb 21, 11:05 pm, Jonathan Mitchem <jmitc...@gmail.com> wrote: > > > > > > > > > I'm new to Lisps in general, and very new to Clojure. > > > When I was trying out CL, I could put my "defun/defn"s in any order in > > the file, and it would load and run fine in the REPL. However, in > > Clojure, it seems to be much more C/C++-like and I have to define > > things before I use them in other defns. > > > Is this... correct? Or is it just a limitation of the IDEs I've been > > trying out? > > > E.g., it seems like I have to define "sum" before I can define > > "average". -- 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