Higher-Order Programming » Lab Sessions

Session 3 (Solutions)

Assistant: Steven Keuchel (steven.keuchel@vub.be)

Section 1: Pairs

Exercise 1.1:





Exercise 1.2:





Exercise 1.3:





Exercise 1.4:





Exercise 1.5:





Section 3: Higher-Order Procedures on Lists

Exercise 3.1: 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 3.2: Filtering





Exercise 3.3: Reversing Lists





Section 4: Higher-Order Procedures on Trees

Exercise 4.1: Sum and depth of a tree





Exercise 4.2: 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