


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Consider the following BNF specification:
follows:
fv( x ) = { x } fv( (lambda (x) e) ) = fv( e ) \ { x }
fv( (e 1 e 2 ) ) = fv( e 1 ) ∪ fv( e2 )
In order to solve this problem, use the procedures that you have defined in problem set 2 and 3.
Solution: (define free-names (lambda (e) (cond ((is-variable? e) (list e)) ((is-abstraction? e) (difference (free-names (caddr e)) (cadr e))) ((is-application? e) (union (free-names (car e)) (free-names (cadr e)))) ) ) ) 15
beta-redex is an application (e 1 e 2 ) where e 1 is an abstraction, that is, it has the form (lambda (x) e 1 ). Note, a beta-redex may occur underneath a lambda-abstraction, that
is, the sub-expression e 1 may contain a beta-redex. Also, in case of a lambda-calculus application (e 1 e 2 ) either e 1 or e 2 may contain a beta-redex.
In order to solve this problem, use the procedures that have been defined in problem set 2.
Solution: define contains-beta-redex? (lambda (e) (cond ((is-variable? e) #f) ((is-application? e) (or (is-abstraction? (car e)) (contains-beta-redex? (car e)) (contains-beta-redex? (cadr e)) )) ((is-abstraction? e) (contains-beta-redex? (caddr e))) ) ) 20 )
Scheme procedures symbol->string , string-append , and string->symbol. Example,
**> (fresh-name 'x '(x y z)) x%
(fresh-name 'x '(x% x%% y z)) x (fresh-name 'x '(x x% x%% y z)) x%%%**
Solution: (define fresh-name (lambda (sym los) (if (member sym los) (fresh-name (string->symbol (string-append (symbol->string sym) "%")) los) sym ) ) ) 15
(caadr e1) (union (free-names e2) (free-names (caddr e1))))))
(list (car e1) (list new-name) (substitution (substitution (caddr e1) (caadr e1) new-name) x e2)) ; rule 6 ) (list (car e1) (cadr e1) (substitution (caddr e1) x e2)) ) ) ----- ) 40 ) ) )
Total: 15 + 15 + 20 + 40 = 90
Submission deadline: Thursday, October 4, 2004, 2:10 p.m.
Submission procedure: on paper in class and electronically using the turnin- hw4 script, which is located in ~cs342/public/bin. Please use the printout of the submission confirmation email as cover page and check the problems that you have solved.
In order to submit your homework solutions, go (using your CS UNIX account) into the directory that contains your solution (i.e., Scheme source files and all related files). In that directory run the command “~cs342/public/bin/turnin-hw4”. After a successful submission, your will receive a confirmation email. Before the due date, you can resubmit your solutions as often as you like.