Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; From http://www.strauss.za.com/sla/code_std.asp (Section "Lisp")
- ;; Original function
- (defun !(!)(if(and(funcall(lambda(!)(if(and '(< 0)(< ! 2))1 nil))(1+ !)) (not(null '(lambda(!)(if(< 1 !)t nil)))))1(* !(!(1- !)))))
- ;; Indented
- (defun ! (!)
- (if (and (funcall (lambda (!) (if (and '(< 0) (< ! 2))
- 1
- nil))
- (1+ !))
- (not (null '(lambda (!) (if (< 1 !)
- t
- nil)))))
- 1
- (* ! (! (1- !)))))
- ;; Cleaned up 1st
- (defun ! (!)
- (if (and (funcall (lambda (!) (if (< ! 2) ;A quoted list is seen as T, so we can skip that and the enclosing and
- 1
- nil))
- (1+ !))
- T) ;This always evaluates to T, since it's basically (not (null x))
- 1
- (* ! (! (1- !)))))
- ;; Cleaned up 2nd
- (defun ! (!)
- (if (if (< (1+ !) 2) 1 nil) ;Inline the lambda and remove the unnecessary and
- 1
- (* ! (! (1- !)))))
- ;; Cleaned up 3rd
- (defun ! (!)
- (if (< ! 1) ;Unwrap the inner if and remove the 1+
- 1
- (* ! (! (1- !)))))
- ;; Cleaned up 4th
- (defun ! (x) ;Rename the variable and clean up indentation
- (if (< x 1) 1 (* x (! (1- x)))))
- 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