Question: Consider the following syntax for a term in the unsugared untyped calculus, represented as an s-expression: E ::= ( V E) | (E E) |

Consider the following syntax for a term in the "unsugared" untyped calculus, represented as an s-expression: E ::= ( V E) | (E E) | V.where V is a variable.

For example, the term fx.f(tgg) would be de-sugared to f.x.f((tg)g) and then represented as the s-expression ( f ( x (f ((t g) g)))). Write a scheme function fv which takes an s-expression of this sort, and returns a list of the free variables. E.g,

(fv '( f ( x (f ((t g) g)))))  (t g) 

or (g t).

N.B = I have tried to problem and asked on Chegg so many times but everytime I output I keep getting:

car: contract violation, expected: pair? given: #

Would appreciate some help on modifications and whats wrong with the code and why it keeps getting car violations?

Consider the following syntax for a term in the "unsugared" untyped calculus,

123456789101112131415161718192021222324252627(define(fvsexp)(cond[(variable?sexp)(listsexp)][(lambda?sexp)(fv(cdrsexp))][(application?sexp)(union(fv(carsexp))(fv(cdrsexp)))]))(define(unionset1set2)(cond[(empty?set1)set2][(member?(carset1)set2)(union(cdrset1)set2)][else(cons(carset1)(union(cdrset1)set2))]))(define(member?itemset)(cond[(empty?set)#f][(equal?item(carset))#t][else(member?item(cdrset))]))(define(variable?sexp)(symbol?sexp))(define(lambda?sexp)(and(pair?sexp)(eq?(carsexp))))(define(application?sexp)(pair?sexp))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!