Programming Assignment 1 (due midnight 02/05/14 02/09/14 02/11/12)

Penalty for late submission: 10% less credit/day.

Implement, document (i.e. provide specifications), and test the following functions in scheme. Scheme has implemented some of the constructs below (iota, association lists) - you may not use these implementations, but rather must implement them yourself. Make sure all functions are thoroughly tested.

  1. The Matlab language supports a convenient notation for specifying ranges of numbers. The notation start:step:end denotes the range of integers start, start+step, start+2*step,...,start+n*step, where n is the largest integer such that start+n*step &le end and start+(n+1)*step > end. Note that the range may be empty if start > end. Write a scheme function (range (start step end)), which returns the list of integers equal to start:step:end. Example:
    > (range '(0 2 7)) 
    ;Value: (0 2 4 6)
    > (range '(2 2 0))
    ;Value: ()
  2. The Maple computer algeba system has a command seq(f, i = m..n, step), which returns the sequence fm,...fn, where fi is the expression f with all occurrences of the symbol i replaced by the numeric value of i in the sequence of integers from m to n. Implement a scheme function (seq f (start step end)), and produces a list of values (f(start),f(start+step),...,f(start+n*step)), where n is the largest integer such that start+n*step &le end and start+(n+1)*step > end. Example:
    > (seq (lambda (x) (* x x)) '(0 2 7))
    ;Value: (0 4 16 36)
  3. Write a scheme function (iterator (start step end)) which returns a function which when repeatedly called returns the numbers in the sequence (range (start step end)). When the sequence is exhausted the returned function should return ().
    > (define next (iterator '(0 2 7)))
    > (begin (next) (next) (next) (next) (next))
    ;Value: 0, 2, 4, 6, ()
  4. An association list is a list of bindings of names to values: ((name1 val1) ... (namet valuet)). This data structure can be used to implement a symbol table. An environment can be represented by a list of association lists (i.e. a list of symbol tables), where the first element in the list is nearest scope, the second the next surrounding scope, and the last the outermost scope.
    1. Write recursive scheme function (lookup name assoc_list) that returns the binding (pair) whose name equals the given name. If no such binding is found return the null list. Example:
      > (define myList '((a 1) (b 2) (c 3)))
      > (lookup 'b myList)
      ; (b 2)
      > (lookup 'd myList)
      ; ()
    2. Write a recursive function (lookup-env name environment), which returns the binding with the specified name in an environment (i.e. list of association lists) and null if no such binding is found. Example:
      > (define myList '((a 1) (b 2) (c 3)))
      > (define myList2 '((d 8) (e 9) (f 10)))
      > (define envList (list myList myList2) )
      > (lookup-env 'd envList)
      ;Value 14: (d 8)

Each programming problem is worth 25 points.

Submission Guidelines

  1. Assignments must be submitted via Email.
    Email the Assignment to
    CC a copy to Professor Nowak
  2. The Title of the Email must be [CS360] Programming Assignment 1
  3. Attach all solutions in a single zip or tar.gz file. Name the file or username_a1.tar.gz where username is your drexel login. For example, mine would be Here is a useful website for making zip/tar.gz/etc in linux
  4. In the body of the email list all the files you are submitting. Give the name of the compressed file and a list of the contents. If any files are missing/corrupted, then I will know what you submitted.
  5. Submit one text file for each question. You should submit four files range.scm, sequence.scm, iterator.scm, and lookup.scm. Put the lookup and lookup-env functions in the same file.
  6. Each file should contain:
    1. Your Name
    2. Comments documenting all functions included in the file
    3. Your function definition
    4. Tests for your functions
  7. Submit a readme file containing the following:
    1. Your Name
    2. Email Address
    3. Example Execution Traces testing each of your functions
  8. All your code MUST run on in mit-scheme.

Other Notes

Here is a good example of how to use the set! command in scheme