Exercises |
|
|
|
Do a step by step hand evaluation of the following Jam expressions:
let or := map x,y to if x then true else y; member := map x,l to if null?(l) then false else or(x = first(l), member(x, rest(l))); in member (1, cons(1, null))
Do it one time using call-by-value and another time using call-by-name
let or := map x,y to if x then true else y; member := map x,l to if null?(l) then false else or(x = first(l), member(x, rest(l))); zeroes := cons(0, zeros); in member (1, zeros)
Do it one time using call-by-value/lazy-cons evaluation and another time using call-by-name/lazy-cons
let or := map x,y to if x then true else y; member := map x,s to if null?(s) then false else or(x = first(s), member(x, rest(s))); countup := map x to cons(x, countup(1+x)); in member (1, countup(0))
Do it one time using call-by-value/lazy-cons evaluation and another time using call-by-name/lazy-cons
Note: the lazy semantics for cons are reflected by three changes to our evaluation rules:
Note that this semantics corresponds to lazy call-by-name. For functional Jam, the difference between lazy call-by-name call-by-need can only be detected because the equality operator is not purely functional (when comparing functions). None of our examples will involve this operation.