I don't really love the readability of letfn all that much, so I'd
normally just:

(defn double-square [y]
        (let [square (fn [x] (* x x))]
            (+ (square y) (square y))))

You also get a chance to use the let to bind other things to improve
readability.

On 15 November 2014 16:38, Gary Verhaegen <[email protected]> wrote:
> defn (actually def, as defn is just a macro wrapping it) is always global,
> no matter where it appears.
>
> It is usually considered bad form to have a def outside the top level,
> though there are exceptions.
>
>
> On Saturday, 15 November 2014, Udayakumar Rayala <[email protected]>
> wrote:
>>
>> Hi,
>>
>> Is it idiomatic to have defn inside defn? eastwood throws def-in-def
>> warning when I have the following code:
>>
>> (defn double-square [y]
>>         (defn square [x] (* x x))
>>         (+ (square y) (square y)))
>>
>> The above code is a simplified example to show the problem. In the above
>> case, square is a function which is local and I dont want it to be shared
>> outside the context of double-square.
>>
>> I can change it to use letfn like below:
>>
>> (defn double-square [y]
>>         (letfn [(square [x] (* x x))]
>>                 (+ (square y) (square y))))
>>
>> But when you have multiple local functions, it doesnt seem nice to read.
>>
>> - Uday.
>>
>> --
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "ClojureScript" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/clojurescript.
>
> --
> Note that posts from new members are moderated - please be patient with your
> first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to