« Return to index

HOP WPO 2 (Solutions)

Assistant: Bjarno Oeyen (bjarno.oeyen@vub.be)

General Remarks

Section 1: Box-and-pointer Diagrams

Exercise 1: Simple box-and-pointer diagram

Exercise 2: Advanced box-and-pointer diagrams

Exercise 3: Shared memory in box-and-pointer-diagrams

Before set-car!:

After set-cdr!:

Section 2: Higher-Order Procedures on Lists

Exercise 4: Sum


sum can also be implemented using the higher-order procedure apply:


The + procedure takes an arbitrary amount of arguments. E.g. in order to calculate \(a+b+c+d\), you can type (+ a b c d) instead of (+ a (+ b (+ c d))). apply applies the given procedure on a list of arguments.

Exercise 5: Filtering


Section 3: Higher-Order Procedures on Trees

Exercise 6: Sum and depth of a tree


Exercise 7: Mapping the values on a tree.

During the exercise session, the solution to this exercise was given in error. This has been corrected.


Bonus Questions

Bonus Exercise 1: Cycle


This program displays #0=(8 5 3 . #0#).

Bonus Exercise 2: Generic Function Composition