Guest User

Code for http://stackoverflow.com/q/20393589/1281433

a guest
Dec 5th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.73 KB | None | 0 0
  1. ;; http://stackoverflow.com/q/20393589/1281433
  2. ;; Joshua Taylor, 4 December 2013
  3.  
  4. (defun length1 (list)
  5.   (if (endp list)
  6.       0
  7.       (+ 1 (length1 (rest list)))))
  8.  
  9. (defun length2 (list)
  10.   (labels ((l2 (list len)
  11.              (if (endp list)
  12.                  len
  13.                  (l2 (rest list) (1+ len)))))
  14.     (l2 list 0)))
  15.  
  16. (defun length3 (list)
  17.   (do ((list list (rest list))
  18.        (len 0 (1+ len)))
  19.       ((endp list) len)))
  20.  
  21. (defun ack2 (x y)
  22.   (do () ((zerop x) (1+ y))
  23.     (if (zerop y)
  24.         (setf x (1- x)
  25.               y 1)
  26.         (psetf x (1- x)
  27.                y (ack2 x (1- y))))))
  28.  
  29. (defun ack3 (x y)
  30.   (do ((x x (1- x))
  31.        (y y (if (zerop y) 1 (ack3 x (1- y)))))
  32.       ((zerop x) (1+ y))))
Add Comment
Please, Sign In to add comment