John Thingstad <john.thingstad@chello.no> wrote:
+---------------
| Nils M Holm <before-2007-01-01@online.de> wrote:
| > (define (depth a)
| > (cond ((pair? a)
| > (+ 1 (apply max (map depth a))))
| > (else 0)))
|
| Thanks! Translating gives:
|
| (defun depth (tree)
| (if (consp tree)
| (1+ (apply #'max (mapcar #'depth tree)))
| 0))
|
| But due to a argumant limit of 255 I don't this works in the general case...
+---------------
So use REDUCE instead of APPLY:
(1+ (reduce #'max (mapcar #'depth tree)))
+---------------
| so I use:
| (defun depth (tree)
| (if (consp tree)
| (1+ (loop for item in (mapcar #'depth tree) maximizing item))
| 0))
+---------------
Works, but it's less "functional"... ;-} ;-}
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607