Skip to content

Instantly share code, notes, and snippets.

@wware
Created June 7, 2016 23:47
Show Gist options
  • Save wware/0473830f3e849303d43ef9149211db2e to your computer and use it in GitHub Desktop.
Save wware/0473830f3e849303d43ef9149211db2e to your computer and use it in GitHub Desktop.
(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