Dana Vrajitoru
C311 Programming Languages

Homework 9

Due Date: Thursday, November 12, 2009.

Ex. 1. a Write a function that receives an unlimited number of parameters and computes the product of all of them that are numbers (some may not be). The non-numerical elements should be ignored. If none of the arguments is a number the function should return 0. You will have to use the appropriate type-checking predicate here.

b. Show a few examples of testing this function, both directly and using the built-ins apply and funcall.

Reference. The tree structure and the print in pre-order functions discussed in class: tree.el.

Ex. 2 In this exercise you will write two functions that print the tree in symmetric order: the left subtree, then the root, and then the right subtree. For example, for the tree discussed in class the symmetric order would be:

18 51 5 33 23 7 10

a. Write a simple recursive function.

b. Transform the function into an iterative one using a number of states (probably 3) as in the example shown in class.

c. (optional, 5 extra credit points) Optimize the function written at point b to avoid storing the states on the stack.

Ex. 3 Follow the execution of the iterative function written at point b showing the content of the stack, the current frame, the root of the current tree, and state at each iteration. There are two options for doing this:

Alt. a Write it yourself on paper (or in a text file) "by hand".

Alt. b. Modify the function itself so that it outputs this information instead of printing out the tree only. You can just send in the code of the function instead.