Assignment 4 – Programming with λ

Assignment 4 – Programming with λ

Due Thursday 5/2 1:59pm

Define an encoding for Lisp cons cells, consisting of the following definitions:
  • null, a constant

  • cons, a function that takes two arguments and returns a cons cell

  • isnull, a function that returns true if its argument is null, false if it is a cons cell

  • car, a function that takes a cons cell and returns its first element

  • cdr, a function that takes a cons cell and returns its second element.

Design your encoding so that it satisfies the following equations:
  • (isnull null) = #true

  • (isnull (cons M N)) = #false

  • (car (cons M N)) = M

  • (cdr (cons M N)) = N

where the equality relation is the reflexive, transitive, compatible closure of the β, η, and α reductions (axioms).

Using this encoding, define length, which takes a list of booleans and returns the number of cons cells in the list. Booleans and Numbers should both be Church-encoded.

Use the lc language to write your solution. Follow the installation instructions on the GitHub page to set it up in your Racket installation. Be sure to include a reasonable set of test cases for each definition.

Deliverables: Upload your file with the solution to canvas.