Length

From mojo_puzzler
Jump to navigation Jump to search
Return to: Chialisp
Return to: Recursive Functions
(mod (lst)
    (defun length (lst)
      (if (l lst)
          (+ 1 (length (r lst)))
        lst)
      )
    (length lst)
    )

Usage Example 1:

brun '(a (q 2 2 (c 2 (c 5 ()))) (c (q 2 (i (l 5) (q 16 (q . 1) (a 2 (c 2 (c 13 ())))) (q . 5)) 1) 1))' '((10 20))'

2

Usage Example 2:

brun '(a (q 2 2 (c 2 (c 5 ()))) (c (q 2 (i (l 5) (q 16 (q . 1) (a 2 (c 2 (c 13 ())))) (q . 5)) 1) 1))' '((10 20 30))'

3