CS603 Organization of Programming Languages

Due 12 March 2004

**University of Alabama
Department of Computer Science
Spring 2004**

`(last`

`)`

given a non-empty list , return the last element of the list.`(o2`

`)`

that is similar to the function composition function,`o`

. The function`f`

should take*two*arguments, and the function`g`

should take one argument. The definition mathematically is . For example, the code`(val oddSum? (o2 (o not even?) +))`

followed by`(oddSum? 1 2)`

will return`#t`

and`(oddSum? 3 5)`

will return`#f`

.`(id`

`)`

or the identity function, which simple returns its argument .`(curryConst`

`)`

, which is like the function`curry`

, except that it creates a function that takes one argument, ignores it, and always returns the value . For example, given the code`(val return0 (curryConst 0))`

, then`(return0 1)`

returns 0,`(return0 2)`

returns 0, etc.`(funIf`

`)`

that returns a one argument function that does the following. The arguments , , and and all one argument functions. Assume that the name of the single argument of the returned function is`x`

. When the returned function is evaluated, if`(p x)`

is true, then the value`(t x)`

is returned. If`(p x)`

is false, then the value`(f x)`

is returned. For example, given`(val zeroOrValue (funIf even? id return0)`

, then the following ensues:-> (zeroOrValue 1) 0 -> (zeroOrValue 2) 2 -> (zeroOrValue 3) 0 -> (zeroOrValue 4) 4

`(sumEvens`

`)`

where is a list of numbers, returns the sum of the elements of which are even. For example`(sumEvens `(1 2 3 4))`

returns 6. You may use`map`

and`foldl`

as defined in the textbook, as well as any of the functions from this MP (hint!).**However**, the body of`sumEvens`

must*not*contain any conditionals (`if`

statements).

`MP2.scm`

.
In your email, set the subject line to ``CS603MP2''.
The attachment should contain your name, set out as a comment.
For example:
; Joel Jones (define add1 (x) (+ x 1))

CS603 Organization of Programming Languages

Due 12 March 2004

This document was generated using the
**LaTeX**2`HTML` translator Version 2K.1beta (1.61)

Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.

Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.

The command line arguments were:

**latex2html** `-split 0 -nonav MP2.tex`

The translation was initiated by on 2004-03-06

2004-03-06