Advertisement
Shinmera

Untitled

May 24th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.58 KB | None | 0 0
  1. ;; From http://www.strauss.za.com/sla/code_std.asp (Section "Lisp")
  2.  
  3. ;; Original function
  4. (defun !(!)(if(and(funcall(lambda(!)(if(and '(< 0)(< ! 2))1 nil))(1+ !)) (not(null '(lambda(!)(if(< 1 !)t nil)))))1(* !(!(1- !)))))
  5.  
  6. ;; Indented
  7. (defun ! (!)
  8.   (if (and (funcall (lambda (!) (if (and '(< 0) (< ! 2))
  9.                                     1
  10.                                     nil))
  11.                     (1+ !))
  12.            (not (null '(lambda (!) (if (< 1 !)
  13.                                        t
  14.                                        nil)))))
  15.       1
  16.       (* ! (! (1- !)))))
  17.  
  18. ;; Cleaned up 1st
  19. (defun ! (!)
  20.   (if (and (funcall (lambda (!) (if (< ! 2)    ;A quoted list is seen as T, so we can skip that and the enclosing and
  21.                                     1
  22.                                     nil))
  23.                     (1+ !))
  24.            T)                                  ;This always evaluates to T, since it's basically (not (null x))
  25.       1
  26.       (* ! (! (1- !)))))
  27.  
  28. ;; Cleaned up 2nd
  29. (defun ! (!)
  30.   (if (if (< (1+ !) 2) 1 nil)                  ;Inline the lambda and remove the unnecessary and
  31.       1
  32.       (* ! (! (1- !)))))
  33.  
  34. ;; Cleaned up 3rd
  35. (defun ! (!)
  36.   (if (< ! 1)                                  ;Unwrap the inner if and remove the 1+
  37.       1
  38.       (* ! (! (1- !)))))
  39.  
  40. ;; Cleaned up 4th
  41. (defun ! (x)                                   ;Rename the variable and clean up indentation
  42.   (if (< x 1) 1 (* x (! (1- x)))))
  43.  
  44. So, the only really important statement all along was (* !(!(1- !))), which is basically a recursive factorial implementation.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement