thanks,
I'll have a look

On Feb 15, 11:06 am, Vincent Foley <vfo...@gmail.com> wrote:
> I'm not sure if it's "Clojury", but this seems to work:
>
> (defn count-leaves [tree]
>   (if (sequential? tree)
>     (+ (count-leaves (first tree))
>        (count-leaves (rest tree)))
>     (or tree 0)))
>
> user> (count-leaves [1 2 3])
> 6
> user> (count-leaves [1 [2] 3])
> 6
> user> (count-leaves [])
> 0
>
> On Feb 15, 10:55 am, wubbie <sunj...@gmail.com> wrote:
>
> > Hi,
>
> > Trying to convert to clojure but stumbled on it...
>
> > (defun count-leaves (tree)
> >   (if (atom tree)
> >   1
> >   (+ (count-leaves (car tree))
> >     (or (if (cdr tree) (count-leaves (cdr tree)))
> >         1))))
>
> > > (count-leaves ’((a b (c d)) (e) f))
>
> > 10
>
> > My clojure version is:
>
> > user=> (defn count-leaves
> >   [tree]
> >    (if (seq tree)
> >      (+ (count-leaves (first tree))
> >         (or (if (rest tree) (count-leaves (rest tree)))
> >             1))
> >      1))
> > #'user/count-leaves
> > user=> (count-leaves [1 2 3])
> > java.lang.IllegalArgumentException: Don't know how to create ISeq
> > from: Integer (NO_SOURCE_FILE:0)
>
> > But not working. I'm wondering why...
>
> > thanks,
> > -sun
>
>
--~--~---------~--~----~------------~-------~--~----~
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
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