Skip to content

Instantly share code, notes, and snippets.

@jestinepaul
Created November 10, 2011 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jestinepaul/1354489 to your computer and use it in GitHub Desktop.
Save jestinepaul/1354489 to your computer and use it in GitHub Desktop.
Introduction to Functional Programming - Part 1
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