0 Members and 1 Guest are viewing this topic.
(defun depth (x) (cond ((atom x) -1) (t (max (1+ (depth (car x))) (depth (cdr x)))) ))
could it be that there's a misprint in the book, shouldn't it be -1?and there is no need to define max_ function, we can use built-in max insteadCode: [Select](defun depth (x) (cond ((atom x) -1) (t (max (1+ (depth (car x))) (depth (cdr x)))) ))
(setq alist '(((((("A") ("a\"(((())))") ((1 . 2)) ))((((((((((((((((((((((("B" ("C"))))))))))))))))))))))))("C")))) ); -> 26Elapsed milliseconds / relative speed for 65536 iteration(s): (DEPTH ALIST).....2000 / 1.53 <fastest> (FOO#5 ALIST).....3063 / 1 <slowest>
(defun ALE_List_NestedLevel4 (l / r s e c i o m) (setq i (vl-prin1-to-string l) s 0 c -1 o 0) (while (vl-string-position 92 i) (setq i (vl-string-subst "" "\\\"" i))) (while (setq e (vl-string-position 41 i s)) (cond ( (= "\"" (setq r (substr i (setq s (1+ s)) 1))) (setq s (1+ (vl-string-position 34 i s))) ) ( (= "(" r) (setq c (1+ c)) ) ( (= ")" r) (setq o (max c o) c (1- c)) ) ( (or (not (setq m (vl-string-position 40 i (1- s)))) (> m e)) (setq s e) ) ) ) o)
(ALE_List_NestedLevel4 '("\\\""))
Code: [Select](ALE_List_NestedLevel4 '("\\\""))