MP2
CS603 Organization of Programming Languages
Due 12 March 2004

University of Alabama
Department of Computer Science
Spring 2004

Purpose

The purpose of this assignment is to provide an opportunity for you to do some programming in the $\mu$-Scheme language.

Problem Description

Write the following $\mu$-Scheme functions.
  1. (last $L$) given a non-empty list $L$, return the last element of the list.

  2. (o2 $g$ $f$) 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 $(g \cdot f)(x,y)$. 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.

  3. (id $x$) or the identity function, which simple returns its argument $x$.

  4. (curryConst $c$), which is like the function curry, except that it creates a function that takes one argument, ignores it, and always returns the value $c$. For example, given the code (val return0 (curryConst 0)), then (return0 1) returns 0, (return0 2) returns 0, etc.

  5. (funIf $p$ $t$ $f$) that returns a one argument function that does the following. The arguments $p$, $t$, and $f$ 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
    

  6. (sumEvens $L$) where $L$ is a list of numbers, returns the sum of the elements of $L$ 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).

How to Turn In the Program

Your program will be extracted and executed programatically. In particular, be sure that the function names you use match the ones in the assignment exactly. Also, be sure that the program is sent to me correctly. Email the source code to me as a single attachment, named 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))

About this document ...

MP2
CS603 Organization of Programming Languages
Due 12 March 2004

This document was generated using the LaTeX2HTML 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