On Sun, Sep 4, 2011 at 11:40 AM, Dennis Haupt <d.haup...@googlemail.com> wrote:
>> - Nested defns are not good.
> why? imo, nested function/method definitions are a tool to fine-tune
> accessibility. just like public/private, but much more powerful. why

Right, but defn binds function names at the top-level (which is why
it's considered poor form to nest them - it doesn't create nested
functions). So those functions are actually all public in that
namespace:

user=> (defn foo[a] (defn bar[b] (* a b)))
#'user/foo
user=> (foo 2)
#'user/bar
user=> (bar 3)
6
user=> (meta #'user/bar)
{:ns #<Namespace user>, :name bar, :file "NO_SOURCE_PATH", :line 1,
:arglists ([b])}

See how bar is defined when foo is called but it is callable directly
in the user namespace?

Using let or letfn creates locally scoped functions, which is what you want.

> again, why? the functions belong there, and nowhere else. they do not
> make sense outside the winner-function. they use parameters which are
> in scope there. factoring them out would actually make them more
> complex since i would have to add more parameters to their signatures.

You can define functions private to your namespace with defn- and you
can define them locally to other forms with let/letfn.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

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