Exercises

 

 

 

Do a step by step hand evaluation of the following Jam expressions:

  1.  
       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

  2.    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

  3.    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:

  • cons(M,N) is a value for all expressions M,N.
  • first(cons(M,N)) = M
  • rest(cons(M,N)) = N
  • Back to course website