Created
June 7, 2016 23:47
-
-
Save wware/0473830f3e849303d43ef9149211db2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (factorial n) | |
;; tail recursion is fast, and often requires a helper function | |
(define (helper n product) | |
(if (< n 2) | |
product | |
(helper (- n 1) (* n product)))) | |
(helper n 1)) | |
;; Scheme looping structure | |
(do | |
((n 100 (+ n 100))) ;; variable, initial value, step | |
((> n 1000) 3) ;; terminating condition and return value | |
(format #t "~s ~s\n" n (factorial n))) ;; Scheme's printf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment