Length

From mojo_puzzler
Revision as of 15:52, 17 November 2023 by Gneale (talk | contribs) (Created page with "===== 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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