On Feb 21, 10: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".

Yes, this is the way things are. If you want to get around it, you can
(declare sum), and there are various macros available if you want to
go more whole-hog and declare things in reverse order.

For example:

(defmacro do-top-down [& forms]
  (cons 'do (reverse forms)))

(do-top-down
  (defn average [& args]
    (/ (sum args) (count args)))
  (defn sum [& args]
    (reduce + args)))

-- 
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

Reply via email to