Project Report for Python, Ocaml, Small Talk | CS 3723, Papers of Programming Languages

Material Type: Paper; Class: Programming Languages; Subject: Computer Science; University: University of Texas - San Antonio; Term: Spring 2009;

Typology: Papers

Pre 2010

Uploaded on 07/30/2009

koofers-user-yfj
koofers-user-yfj 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS3723 Extra-credit projects
due May 3, 2009 (submit by emailing to the instructor)
1. (6pts) Write a survey paper that studies one of the following languages in depth.
(a) Python
(b) Perl
(c) SmallTalk
(d) Ocaml
For the language that you have picked to study, summarize
What is the language designed for? What is special about the language?
What principle data types does it support?What operations does it support?
What control-flow does it support?What programming paradigm does it belong?
How is it implemented? Is it sufficiently expressive to serve it’s purpose? Is it
efficiently implemented?
What is it commonly used for? How does it compare to the other languages we
have learned so far?
How should one write programs in this language. How is it different comparing
to programming in C, Scheme, and ML?
If you would like to study a language not listed above, talk to the instructor to get
approval.
2. (6pts) Evaluating lambda calculus. Using either Scheme or ML, define a function
“eval-lambda”, which serves as an interpreter for pure-lambda calculus. This function
takes a single expression exp as parameter, performs all the βreductions allowed in
exp to reduce it to a normal form, and finally returns the reduction result.
Each lambda term is internally represented using an AST, which can be implemented
using a nested list data structure in Scheme or using the following datatype definition
in ML.
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.
1
pf2

Partial preview of the text

Download Project Report for Python, Ocaml, Small Talk | CS 3723 and more Papers Programming Languages in PDF only on Docsity!

CS3723 Extra-credit projects

due May 3, 2009 (submit by emailing to the instructor)

  1. (6pts) Write a survey paper that studies one of the following languages in depth.

(a) Python (b) Perl (c) SmallTalk (d) Ocaml For the language that you have picked to study, summarize

  • What is the language designed for? What is special about the language?
  • What principle data types does it support?What operations does it support?
  • What control-flow does it support?What programming paradigm does it belong?
  • How is it implemented? Is it sufficiently expressive to serve it’s purpose? Is it efficiently implemented?
  • What is it commonly used for? How does it compare to the other languages we have learned so far?
  • How should one write programs in this language. How is it different comparing to programming in C, Scheme, and ML? If you would like to study a language not listed above, talk to the instructor to get approval.
  1. (6pts) Evaluating lambda calculus. Using either Scheme or ML, define a function “eval-lambda”, which serves as an interpreter for pure-lambda calculus. This function takes a single expression exp as parameter, performs all the β reductions allowed in exp to reduce it to a normal form, and finally returns the reduction result. Each lambda term is internally represented using an AST, which can be implemented using a nested list data structure in Scheme or using the following datatype definition in ML.

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.

  1. (6pts) Using either Scheme or ML, write a function EvalExpT ype to evaluate the types of expressions. This function should take two parameters: table, which con- tains a collection of name-type pairs and remembers the type of each variable used within an expression; and exp, an arithemetic expression that could contain numbers, variables (the name of a variable can be implemented using symbols in Scheme or strings in ML), lists, and operations including +, −, ∗, /, cons, car and cdr. Your EvalExpT ype function is supposed to apply static type checking to the given expres- sion exp, assuming the types of all variables in exp are declared in table, and returns the type of exp as result. For each variable x in exp, you need to define a f ind func- tion which can returns the type of x in table. Your type system must support two basic types: number and symbol, which are represented using ’symbol and ’number in Scheme respectively. Your type system must also support a compound type, list, which is represented in Scheme as (′list comp), where comp is the type of components in the list. The following enumerates some of the valid types you must support: ’sym- bol, ’number, (’list ’symbol), (’list ’number), (’list (’list ’number)),etc. These types can be represented in ML using the following datatype definition.

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).