Created
November 10, 2011 09:26
-
-
Save jestinepaul/1354489 to your computer and use it in GitHub Desktop.
Introduction to Functional Programming - Part 1
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
4 | |
"Hello" | |
#t | |
#f | |
11.752 | |
11/5 | |
22/4 | |
(+ 1 2 4) | |
(* (+ 4 4) | |
(+ 5 5)) | |
(and (> 4 2) | |
(> 10 5)) | |
(car '(1 2 3 4 5)) | |
(cdr '(1 2 3 4 5)) | |
(car (cdr (cdr '(1 2 3 4 5)))) | |
(cons 1 '(2 3 4 5)) | |
(cons '(1 2 3) '(4 5)) | |
(append '(1 2 3) '(4 5)) | |
(define (add x y) | |
(+ x y)) | |
(define (sum-of numlist) | |
(if (null? numlist) 0 | |
(+ (car numlist) | |
(sum-of (cdr numlist))))) | |
(define (fib1 n) | |
(if (zero? n) 0 | |
(if (= n 1) 1 | |
(+ (fib1 (- n 1)) | |
(fib1 (- n 2)))))) | |
(define (fib2 n) | |
(if (or (= n 0) | |
(= n 1)) n | |
(+ (fib2 (- n 1)) | |
(fib2 (- n 2))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment