Hi Jim,

Thanks so much! Using 'def' instead of 'defn' when defining a function
composed of functions was what I was missing.

I can't believe I spent an hour trying to figure this out -- it seems
very obvious now. Doh!

:)

On Nov 8, 6:50 pm, Jim Crossley <jcrossl...@gmail.com> wrote:
> Hi
>
> Aquahappy <joshua.ay...@gmail.com> writes:
>
> [...]
>
> > 1:  (define (compose f g) (lambda (x) (f (g x))))
> > 2:  (define (twice f) (compose f f))
> > 3:  (define fourth (twice sq))
> > 4:  (fourth 3)
>
> > I've gotten this far and then I get stuck when I try to do line 2 from
> > the above:
>
> > 1:  (defn compose [f g] #(f (g %)))
>
> This is what I came up with. Note I also defined the sq function.
>
> user=> (defn compose [f g] #(f (g %)))
> #'user/compose
> user=> (defn twice [f] (compose f f))
> #'user/twice
> user=> (defn sq [x] (* x x))
> #'user/sq
> user=> (def fourth (twice sq))
> #'user/fourth
> user=> (fourth 3)
> 81
>
> Jim

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