Another way of looking at Clojure code is not a "top down abstraction first" view, but as the building of a system from smaller parts. The best example of this is clojure/core.clj . Sure it's bootstrap code so it can be a bit verbose at times, but you start with nothing and end up with a complete system. Now picture this in a "top down" style...it'd be insanely complex. Even a "whole program compilation unit" compiler would have problems compiling this code, as some macros like let and loop are redefined in in the same file, and some macros are needed before those more complex forms can even be processed.
Most developers write Clojure code from the REPL in this case, it's pretty simple to compile files exactly the same way. Just as a programmer at the REPL would enter forms one at a time, So the compiler compiles in exactly the same way. The last thing I would want is two forms of compilation, one at the REPL, one during :require. So just a few thoughts. IMO, the simplicity of Clojure's compilation model as it stands now is a major strength, not a "broken" hack. Timothy On Tue, Jun 3, 2014 at 7:32 AM, Gregg Reynolds <d...@mobileink.com> wrote: > > > > On Sun, Jun 1, 2014 at 9:36 AM, Glen Mailer <glenja...@gmail.com> wrote: > >> Hi everyone, I'm looking to get some opinions on code style. >> >> Specifically, I like to write my code in a top-down. >> >> What I mean by that is that within a file the highest-level functions sit >> at the top, and are implemented in terms of lower-level functions further >> down. >> > ... > >> The problem now is because of the single-pass nature of clojure's >> evaluation - simply writing code like this doesn't actually work. >> >> There's a few approaches i've seen from reading other's code: >> >> 1. Have an "impl" namespace which contains all of the helper functions >> for the public "interface" >> 2. Make use of (declare) forms where necessary to improve forward >> readability >> 3. Don't worry about source order, just have the api functions further >> down the file and live with it >> > > 4. Put your helper funcs ("defn-" stuff) in helpers.clj, without a call > to ns at the top, then (load "helpers") at the top of the file that uses > them. You still get the effect you're looking for, with a one line > "preface" that tells the reader where to look for more info. Seems to work > in a little test app (lein new app topdown): > > ;; in topdown/core.clj: > (ns topdown.core > (:gen-class)) > > (load "helpers") > > (defn -main > "I don't do a whole lot, but I do call an internal function that lives > in another source file." > [& args] > (hello)) > > ;; in topdown/helpers.clj: > ;; internal topdown helper fns > > (defn- hello [] (println "Hello")) > > > HTH > > Gregg > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.