Created
December 24, 2013 18:39
-
-
Save christianromney/8116652 to your computer and use it in GitHub Desktop.
Accompany mex.pdf
This file contains 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
#lang racket | |
;; Non-tail | |
(define sum1 | |
(λ (n) | |
(if (= n 0) n | |
(+ n (sum1 (- n 1)))))) | |
(sum1 10) | |
;; Tail call | |
(define sum2 | |
(λ (n) | |
(letrec [(suma (λ (n acc) | |
(if (= n 0) acc | |
(suma (- n 1) (+ acc n)))))] | |
(suma n 0)))) | |
(sum2 10) | |
;; Theorem | |
(define sum3 | |
(λ (n) | |
(/ (+ n (* n n)) 2))) | |
(sum3 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment