diff options
author | Ben Burwell <bburwell1@gmail.com> | 2013-04-11 00:03:50 -0400 |
---|---|---|
committer | Ben Burwell <bburwell1@gmail.com> | 2013-04-11 00:03:50 -0400 |
commit | 5b05b64a2a658c0f7d4eb5b09fa342c7375a776e (patch) | |
tree | bad4537081da8b969084cff6880e36418f13a97d /HW03.rkt |
Init
Diffstat (limited to 'HW03.rkt')
-rw-r--r-- | HW03.rkt | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/HW03.rkt b/HW03.rkt new file mode 100644 index 0000000..b6310a1 --- /dev/null +++ b/HW03.rkt @@ -0,0 +1,42 @@ +#lang scheme + +; ------------------------------------------------------------ +; PROGRAM NAME: HW02.rkt +; +; DESCRIPTION: Second homework assignment for CSI310 +; +; AUTHOR: Ben Burwell ; CS 310: Theory of Programming Languages +; Muhlenberg College +; + +;; --------- +;; NAME: invert +;; DESC: takes a list of 2-lists (lists of length 2), and returns a list with each 2-list reversed. + +(define invert + (lambda (l) + (map swap l))) + +(define swap + (lambda (l) + (if (= 2 (length l)) + (list (cadr l) (car l)) + (display "Error")))) + +;; TEST +(invert '((2 1) (4 3) (6 5))) ;; should return (1 2) (3 4) (5 6) + + +;; --------- +;; NAME: compose23 +;; DESC: that takes 1, 2, or 3 procedures and composes them, as specified by the equation: +;; (compose f g h) = (compose f (compose g h)) + +(define compose23 + (lambda funcs + (if (= (length funcs) 1) + (car funcs) + (if (= (length funcs) 2) + ((car funcs) (cadr funcs)) + (if (= (length funcs) 3) + ((car funcs (cadr funcs) (caddr funcs))))))))
\ No newline at end of file |