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 /hw06/hw06_eta.scm |
Init
Diffstat (limited to 'hw06/hw06_eta.scm')
-rw-r--r-- | hw06/hw06_eta.scm | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/hw06/hw06_eta.scm b/hw06/hw06_eta.scm new file mode 100644 index 0000000..991ee65 --- /dev/null +++ b/hw06/hw06_eta.scm @@ -0,0 +1,50 @@ +#lang eopl + +; Ben Burwell +; Dr. Kussmaul +; CSI-310 :: Programming Languages +; Homework 6: Eta Conversion + +;; ========== PROCEDURE ========== +;; NAME: eta-conv +;; DESC: takes a lambda expression and returns +;; its eta conversion. If the expression +;; does not have an eta-conversion, it +;; returns the expression itself. + +(define eta-conv + (lambda (lst) + (if ;; check that the parameter is a list of length 3 + (and + (list? lst) + (equal? (length lst) 3) + ) + (if ;; it is a list with the correct length, check + ;; that it has an eta-conversion + (and + (equal? (car lst) 'lambda) + (list? (cadr lst)) + (equal? (length (cadr lst)) 1) + (list? (caddr lst)) + (equal? (length (caddr lst)) 2) + (equal? (caadr lst) (cadr (caddr lst))) + ) + + ;; it does, so return the conversion + (car (caddr lst)) + + ;; it doesn't, so return the expression + lst) + + ;; not a parseable expression, return it + lst))) + +;; ========== TEST CODE ========== +;; should return a: +(eta-conv '(lambda (x) (a x))) + +;; should return (lambda (x) (x a)) +(eta-conv '(lambda (x) (x a))) + +;; should return () +(eta-conv '()) |