Code Red > AutoLISP (Vanilla / Visual)

Find the nest level of a list

<< < (8/8)

Marc'Antonio Alessi:
; Just for fun - iterative - string based
; (mapcar 'ALE_List_NestedLevel3 aL) > (1 0 0 0 0 1 2 5 7 24 26 1 2 0)

--- Code: ---(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
)
--- End code ---

VovKa:

--- Code: ---(ALE_List_NestedLevel4 '("\\\""))

--- End code ---

Marc'Antonio Alessi:

--- Quote from: VovKa on October 23, 2017, 05:10:38 PM ---
--- Code: ---(ALE_List_NestedLevel4 '("\\\""))

--- End code ---

--- End quote ---
...maybe it's time to throw the sponge...

Navigation

[0] Message Index

[*] Previous page

Go to full version