X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=assignment1.mdwn;h=560d288ebc4e7687af786a57f1eccb4a67b05fca;hp=93136f22353c02033c4f263082ae015e017b1744;hb=8f9abe589a3b7c615b72adc6cbf57e7de1d931d3;hpb=97fd9ed2423e6c6d9e0dabdce6bc334f8439637f diff --git a/assignment1.mdwn b/assignment1.mdwn index 93136f22..560d288e 100644 --- a/assignment1.mdwn +++ b/assignment1.mdwn @@ -26,30 +26,34 @@ In Racket, these can be defined like this: (define true (lambda (t) (lambda (f) t))) (define false (lambda (t) (lambda (f) f))) -8. [8] Define a "neg" operator that negates "true" and "false". +* Define a "neg" operator that negates "true" and "false". + Expected behavior: - (((neg true) 10) 20) + (((neg true) 10) 20) evaluates to 20, and - (((neg false) 10) 20) + (((neg false) 10) 20) evaluates to 10. -9. [9] Define an "and" operator. +* Define an "and" operator. + +* Define an "xor" operator. -10. [10] Define an "xor" operator. (If you haven't seen this term before, here's a truth table: +(If you haven't seen this term before, here's a truth table: - true xor true = false - true xor false = true - false xor true = true - false xor false = false + true xor true = false + true xor false = true + false xor true = true + false xor false = false ) -* 11. Inspired by our definition of boolean values, propose a data structure -capable of representing one of the two values "black" or "white". If we have +* Inspired by our definition of boolean values, propose a data structure +capable of representing one of the two values "black" or "white". +If we have one of those values, call it a black-or-white-value, we should be able to write: @@ -60,7 +64,7 @@ if-white, depending on which of the black-or-white values we started with. Give a definition for each of "black" and "white". (Do it in both lambda calculus and also in Racket.) -12. Now propose a data structure capable of representing one of the three values +* Now propose a data structure capable of representing one of the three values "red" "green" or "blue," based on the same model. (Do it in both lambda calculus and also in Racket.) @@ -80,8 +84,8 @@ To extract the first element of a pair p, you write: Here are some defintions in Racket: (define make-pair (lambda (fst) (lambda (snd) (lambda (f) ((f fst) snd))))) - (define get-first (lamda (fst) (lambda (snd) fst))) - (define get-second (lamda (fst) (lambda (snd) snd))) + (define get-first (lambda (fst) (lambda (snd) fst))) + (define get-second (lambda (fst) (lambda (snd) snd))) Now we can write: