Clojure style: defn- vs. letfn -


Closer style (and generally good software engineering) puts a lot of emphasis on small functions, which is a subset of public Provide an external interface that is visible.

There are some ways to do this in the closure:

  (letfn [(Private-A ...) (private-B ...)] (public- A ...) (public-b ...) (defn-private-a ...) (defn-private-b ...) (public-A defn ...) (defn public-b ... Letterform form seems more vocabulary and perhaps less flexible, but it reduces the scope of the function.  

My guess is that letfn is used only by other forms Is done only when the small auxiliary function is used only in a small area Is it a consensus? Should it be used at any top level (as I have suggested earlier)? When should it be used?

In the case of letfn it is intended for interpersonal recurrence:

  (letfn [(even ? [N] (If (zero? N) is true (strange? (DC N))) (Strange? [N] (If (zero? N) is wrong (even? (DC N) )))] (Even -42?)) ;; = & gt; true   

its sub Do not do yoga at the top level.

Do not use the defn macro anywhere else at the top unless you have very specific reason to do this DIF Which will create and international trade will be expanded.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -