list.lisp 383 B

12345678910111213141516
  1. (defun reduce (func list &optional init) ;; the use of init here is actually a bit broken wrt null
  2. (let* ((acc))
  3. (do* ((i (if init -1 0) (1+ i))
  4. (acc (if init init (elt list 0)) (func acc (elt list i))))
  5. ((>= i (1- (length list)))))
  6. acc))
  7. (defun car (ls)
  8. (@ ls 0))
  9. (defun cdr (ls)
  10. (chain ls (slice 1)))
  11. (defun reverse (ls)
  12. (chain ls (reverse)))