Yeah Alessi - iterating a string makes sence to be faster.
This is my attempt with it - which ended up a bit more understandable version of Lee's 3rd code (the RJP-Style) :
...
And sorry I'm not that good string manipulator.
(setq alist '(((((("A")))((((((((((((((((((((((("B" ("C"))))))))))))))))))))))))("C")))) ); -> 26
My version works only on one long string:
Comando: (vl-princ-to-string alist)
"((((((A))) (((((((((((((((((((((((B (C)))))))))))))))))))))))) (C))))"
Not with a list of strings:
Comando: (mapcar 'chr (vl-string->list (vl-prin1-to-string alist)))
("(" "(" "(" "(" "(" "(" "\"" "A" "\"" ")" ")" ")" " " "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "(" "\"" "B" "\"" " " "(" "\"" "C" "\"" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" ")" " " "(" "\"" "C" "\"" ")" ")" ")" ")")
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 32768 iteration(s):
(LEEFOORJPSTYLE ALIST)............1547 / 1.88 <fastest>
(ALE_LIST_NESTEDLEVEL2 ALIST).....2406 / 1.21
(NLVLS ALIST).....................2907 / 1 <slowest>
I think that a good solution (not recursive) is to modifiy Lee's LEEFOORJPSTYLE
(defun LEEFOORJPSTYLE ( l / n r x )
(setq l (vl-string->list (vl-prin1-to-string l)) r 0 n -1)
(while (setq x (car l))
(cond
( (= 34 x) (setq l (member 34 (cdr l))))
( (= 40 x) (setq n (1+ n)))
( (= 41 x) (setq r (max n r) n (1- n)))
)
(setq l (cdr l))
)
r
)
to skip numbers as it skip strings...