Hi sun,
This sounds related to tree-flattening. If you search the google
group with keyword "flatten", I think you'll discover some indirectly
useful information.
Kev
On Feb 16, 3:55 am, wubbie wrote:
> So destructuring is essentially doing (first coll) for each parameter
> and the rest i
So destructuring is essentially doing (first coll) for each parameter
and the rest is assigned (rest coll)?
On Feb 15, 11:48 am, wubbie wrote:
> Also how left and right gets mapped magically to (first tree) and
> (rest tree)?
> Is it destructuring? I have some ideas on destructuring but this l
Also how left and right gets mapped magically to (first tree) and
(rest tree)?
Is it destructuring? I have some ideas on destructuring but this left
and right things confuses me...
thanks
sun
On Feb 15, 11:31 am, wubbie wrote:
> thanks,
> it works, although it does not count nil node.
> Anyway
thanks,
it works, although it does not count nil node.
Anyway, what's the motivation behind using "sequential?" ?
thanks
sun
On Feb 15, 11:23 am, Vincent Foley wrote:
> Sorry about the erroneous function, I think this is more likely what
> you want:
>
> (defn count-leaves [[left & right :as tre
Sorry about the erroneous function, I think this is more likely what
you want:
(defn count-leaves [[left & right :as tree]]
(if (seq tree)
(+ (if (sequential? left)
(count-leaves left)
1)
(count-leaves right))
0))
user> (count-leaves [])
0
user> (count-leaves [
Oh duh, I didn't even implement the correct thing! Sorry :(
On Feb 15, 11:06 am, Vincent Foley 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)))
>
thanks,
I'll have a look
On Feb 15, 11:06 am, Vincent Foley 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-le
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,
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
[t