| << Prev | - Up - | Next >> |
Define a functional procedure Append computing the concatenation of two lists. Is your procedure tail recursive?
Define a functional procedure Product which computes the product of a list of integers. For instance, {Product [1 2 3]} should return 6. Is your procedure tail recursive? Do you know of a procedure ProductShort computing the same function than Product but whose code is less than 40 letters long? Does the execution of your procedure ProductShort require constant space?
Some people A, B, C, D, E order wine together. Below you find a table which contains the prices per bottels and the number of bottels ordered per person. How much has everybody to pay?
Prices = [19.3 27. 25. 29.75 26.5 27.5 46.5 15. 32.5]
A = [4 3 0 3 0 6 3 3 1]
B = [0 2 0 4 2 0 0 0 0]
C = [0 0 3 1 1 3 0 0 1]
D = [0 3 3 3 3 3 3 3 2]
E = [2 3 3 1 0 0 0 0 0]Write a functional procedure AppendLists based on FoldL (or FoldR) and Append which transforms the list [[a] [b c [d]] nil [e f]] to a list [a b c [d] e f]. Which variant does need less time, when using FoldL or FoldR? Why?
Write a functional procedure Reverse which reverses a list. What is the worst case complexity for the runtime of your program? If it is not linear then write a linear one SmartReverse, too.
Write an evalutor Eval for arithmetic expressions represented as Oz-terms (without variables). For instance, {Eval times(plus(2 4) 3)} should return 18.
Boolean conditionals and record selection can be used instead of pattern matching even though this is much less conveniant. To see this, write an functional procedure SquareList that does not use a pattern matching conditional.
Write a procedure that inspects all elements of a list without using loops.
Write a functional procedure ToList of type stack->list(value) that converts a stack to its actual contents.
| << Prev | - Up - | Next >> |