Guest User

Untitled

a guest
Dec 8th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.08 KB | None | 0 0
  1. ;;; with default optimizations
  2. (defun factorial (n)
  3.   (cond ((= n 0) 1)
  4.     (t (* n (factorial (- n 1))))))
  5.  
  6. ;;;-----------------------
  7. ;;; usage:
  8. ;;;
  9. ;;; $ clisp, ecl or cmucl
  10. ;;; (load "fact.lisp")
  11. ;;; (test1)
  12. ;;; or
  13. ;;; (test2)
  14.  
  15. ;;; poor, c conversion, :)
  16. #+:clisp
  17. (defun test1 ()
  18.   (format t "~S~&" (factorial 6000)))
  19.  
  20. #+:clisp
  21. (defun test2 ()
  22.   (compile 'factorial)
  23.   (format t "~S~&" (factorial 40000)))
  24.  
  25. ;;;------------------------
  26. ;;; better, :)
  27. #+:ecl
  28. (defun test1 ()
  29.   (format t "~S~&" (factorial 12000)))
  30.  
  31. #+:ecl
  32. (defun test2 ()
  33.   (compile 'factorial)
  34.   (format t "~S~&" (factorial 80000)))
  35.  
  36. ;;;--------------------------
  37. ;;; this is already optimized by default
  38. #+:cmu
  39. (defun test1 ()
  40.   (format t "~S~&" (factorial 100000)))
  41.  
  42. #+:cmu
  43. (defun test2 ()
  44.   (compile 'factorial)
  45.   (format t "~S~&" (factorial 200000)))
  46.  
  47. ;;; Note:
  48. ;;;
  49. ;;; - the numbers are random, that means i didn't try to find a limit,
  50. ;;; just stop before 'stack overflow' for clisp and ecl, first hit
  51. ;;; from cmucl
  52. ;;; - no declaration to optimze the compiled code in a specific way
Add Comment
Please, Sign In to add comment