Homework5-sol - 3 Problem 3(15 Points We say that there are...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 5555 Programming Language Principles Homework 5 *Note: Please submit your solution to the e-learning system by the deadline. No late submission is allowed. 1. Problem 1 (15 Points) If there are two different normal forms of the same program, how can they be transformed to each other? Does a normal form always exist? If yes explain why. If not, give a counter- example. Solution: Normal form is unique except for alpha transformations. Self-replicating RPAL program "(fn x. x x)(fn x. x x)" is non-terminating, i.e., normal form does not exist. 2. Problem 2 (15 Points) What does `left referencing' mean? Name one programming language which is left-referencing and one which is right-referencing. Solution: Left referencing means that the expression on the left has to be an address. RPAL and LPAL are right-referencing and left-referencing respectively.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 3. Problem 3 (15 Points) We say that there are no assignments in RPAL. Then what is `x = 1' in the following RPAL program? let x = 1 in x + 1 Solution: It's a binding. Not an assignment. 4. Problem 4 (15 Points) Are tuples in RPAL evaluated left-to-right or right-to-left? Write a short RPAL program (one line) in which this direction is important for the result. Write down the result under the two different scenarios. Solution: right-to-left. For example "print4, print 5" displays "54" instead of "45". 5. Problem 5 (40 Points) Using the CSE machine, evaluate the following RPAL program. Show the output of the program (if any), and the environment structure. let rec f n = n eq 1 -> 1 | n + f (n-2) in f 5 Solution: NOTE: Output is actually 9...
View Full Document

{[ snackBarMessage ]}

Page1 / 5

Homework5-sol - 3 Problem 3(15 Points We say that there are...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online