

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Paper; Class: Programming Languages; Subject: Computer Science; University: University of Texas - San Antonio; Term: Spring 2009;
Typology: Papers
1 / 2
This page cannot be seen from the preview
Don't miss anything!


(a) Python (b) Perl (c) SmallTalk (d) Ocaml For the language that you have picked to study, summarize
datatype LambdaTerm = Var of int | Lambda of int * LambdaTerm | Apply of LambdaTerm * LambdaTerm;
Note that we use an integer to uniquely identify each variable in the lambda term. For example, the lambda term (λ x. x) y can be represened using a nested list ’((lambda 1 1) 2) in Scheme and using the datatype value Apply(Lambda(1, V ar(1)), V ar(2)) in ML. In order for your interpreter to work, you will need to define additional functions such as the following.
(a) A function “free?”, which takes two parameters, an integer x and an lambda term AST exp. The function may return true if it can find x as a free variable in exp, and will return false otherwise. (b) A function “substitute”, which takes three parameters, an integer x, a lambda term AST y, and a lambda term AST exp. This function will return another lambda term AST such that all free occurances of x in exp are replaced with y. (c) A function “beta” which implements the β reduction of lambda calculus. This function takes three parameters: an integer var and two lambda expressions arg and exp. It returns the result of trying to replace all occurrences var in exp with arg without accidentally binding free variables in arg. That is, if exp contains a sub-expression exp1=(lambda 2 ...) and 2 occurs as a free variable in arg, before replacing occurrences of var in exp1, the function “beta” first replaces all occurrences of 2 in exp1 with a new unique integer.
datatype Type = Symbol | Number | List of Type | Error of string;
If there are errors within the given expression or table, your function can simply return the Error type as result (where the string indicate any information relevant to the error).