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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---