Skip to content

Instantly share code, notes, and snippets.

@cleac
Last active May 29, 2017 21:32
Show Gist options
  • Save cleac/0e9536b9c3cc867e9dabbd0c611f1395 to your computer and use it in GitHub Desktop.
Save cleac/0e9536b9c3cc867e9dabbd0c611f1395 to your computer and use it in GitHub Desktop.
A factorial implementation in lisp
; More functional approach, but it gets a stack overflowed on huge numbers
(defun factorial(num)
(cond
((< num 1) 1)
(t (* (factorial (- num 1)) num))
)
)
(defun factorial(num)
(let ((result 1))
(loop
(setq result (* result num))
(setq num (- num 1))
(when (< num 1) (return result))
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment