Lab 5
1 Warmup
2 Continuing on:
3 Reasonable Practice
4 Very Hard
6.2.0.3

Lab 5

For these programs, you may use only "lambda" to define your functions, and the solution to each problem must be a single scheme term, defined using a ’define’.

In addition, the solution to each problem must consist *only* of lambda terms with exactly one argument, applications, and variable references. No if, no cond, no numbers, no primitive functions, etc.

Please note that it’s fine to use these things in your test cases, which are otherwise very hard to read.

So, for instance: define a function p1 that takes a value ’v’ and a function ’f’ (in that order) and just returns ’v’:

;; solution
(define p1 (lambda (v) (lambda (f) v)))
 
;; test case:
(test ((p1 8) (lambda (x) 1234)) 8)

Note that the solution doesn’t use numbers, just the test case.

1 Warmup

2 Continuing on:

  1. Define a function called two that accepts a function and an argument and applies the function to the result of applying the function to the argument.

  2. Define a function called zero that accepts a function and an argument and returns the argument.

  3. Let’s use the term “number-like functions” for functions like zero, one, and two. Define a function called add1 that accepts a number-like function and returns a new number-like function that does the function "one more time". So, for instance, calling add1 with two should produce the function that applies its first argument to its second argument three times. This function should not use racket’s numbers at all, just the number-like functions described above.

  4. Define a function called ’add’ that accepts two functions like zero and one and returns a function that applies its first argument to its second argument a number of times that corresponds to the sum of the two ’numbers’ it was given. So, if called with the ’three’ function and the two function, it should produce a function that applies its first argument to its second argument five times.

  5. Define a function called tru that accepts two arguments and returns the first one.

  6. Define a function called fals that accepts two arguments and returns the second one.

  7. Define a function called ’if’ that accepts three arguments. If the first one turns out to be the function tru (as above), it returns the result of the second argument. If the first one turns out to be the function fals (as above), it returns the result of the third argument.

    This function should not use any of racket’s conditional operators (if, cond, etc.) Show me this function for lab credit.

3 Reasonable Practice

Express these functions as terms in the GUCI3 language, and embed them in test cases.

4 Very Hard