Hi,

2010/2/25 Meikel Brandmeyer <m...@kotka.de>

> Hi,
>
> On Feb 25, 11:24 am, reynard <atsan...@gmail.com> wrote:
> > I define a function foo in which it calls an auxiliary function bar,
> > which is not yet defined, and a compiler exception is raised claiming
> > unable to resolve symbol bar.
> >
> > Is there a way that I can define the functions in any order I want,
> > without taking care of defining the auxiliary function first?  Thanks.
>
> (declare bar)
> (defn foo ...)
> ....
> (defn bar ...)
>

I just thought about it, but a very simple macro one could name 'dotopdown
could help organize parts of code in a "top down first" approach:

(defmacro dotopdown
  "children forms inside the call to dotopdown will be evaluated in the
reverse order, thus allowing a more 'top down first' approach."
  [& body]
  `(do ~@(reverse body)))

So you can with have the important functions of a group of related functions
written first, and the functions definitions on which the important function
relies upon written last.
(note you'll need to exactly revert the dependency graph order : if you have
f1 -> f2 & f3 , f2 -> f3, then you'll define in this order : [f1, f2, f3],
the exact inverse order of [f3, f2, f1])

A little example:

(dotopdown
  (defn print-hello [n] (printf (say-hello n)))
  (defn- say-hello [n] (str "hello " n)))

HTH,

-- 
Laurent

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