aboutsummaryrefslogtreecommitdiff
path: root/HW03.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'HW03.rkt')
-rw-r--r--HW03.rkt42
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