hw2 - calc Function Write a Function unparse WAE> sexp It...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 558 Homework 2 – due 2pm, Wednesday, January 20, 2010 Homework must be submitted by mail to [email protected] , with the subject line “ HW2 ”. Note that this is is a change from Homework 1! Place all your solutions in a Scheme fle named sol2.ss and send this is a plain-text attachment to the mail message (the contents oF the message itselF will be ignored). It is your responsibility to submit the homework in the proper Format. General rules: Your fles must start with the language declaration #lang planet plai/plai:1:6 . You must provide a sensible set oF tests (using the PLAI test Form) For each top-level Function you defne. No credit without the tests. ±or questions that call For English text, just put your answers in a block comment. Try to stick to the subset oF Scheme Forms that were introduced in Homework 1. 1. In fle hw2.ss you will fnd an implementation oF the WAE interpreter From PLAI Chapter 3, including a type defnition, expression parser, substitution Function, and
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: calc Function. Write a Function unparse : WAE -> sexp . It should be the leFt inverse oF parse ; that is, iF (parse s) succeeds, then (equal? (unparse(parse p)) p) returns #t . 2. (a) Write a Function lazy-calc : WAE -> number , which is the same as calc except that it uses the “lazy” regime described in PLAI Section 3.4. (a) Give a WAE expression that contains n ’+ operators, and that perForms O ( n ) add operations when evaluated by calc but O (2 n ) add operations when evaluated by lazy-calc . (b) Does lazy-calc always perForm at least as many ’+ operations as calc on a given WAE expression? Prove that this is so, or give a counter-example. 3. Your WAE interpreter behaves di²erently than C/C++/Java/C# when doing arithmetic on integers. Give some examples oF these di²erences. Hint: Think about large numbers. 1...
View Full Document

This note was uploaded on 01/30/2010 for the course CSE 581 taught by Professor Jameshook during the Spring '09 term at Portland State.

Ask a homework question - tutors are online