X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?a=blobdiff_plain;f=assignment1.mdwn;h=12cd7059b502f2034da572c9b71c14132c00ca43;hb=58b1fb955b3b242e0c8ac9a0c5c092cbee5d5fbf;hp=9be95780ca0faf912b436a7fe13e81f0d6c0cf8d;hpb=d541a6500e8d82e1a8862924dca00c360d482c6a;p=lambda.git diff --git a/assignment1.mdwn b/assignment1.mdwn index 9be95780..12cd7059 100644 --- a/assignment1.mdwn +++ b/assignment1.mdwn @@ -1,4 +1,5 @@ -**Reduction** +Reduction +--------- Find "normal forms" for the following (that is, reduce them as far as it's possible to reduce them): @@ -12,7 +13,8 @@ them): 7. (\x (x x x)) (\x (x x x)) -**Booleans** +Booleans +-------- Recall our definitions of true and false. @@ -24,22 +26,32 @@ In Racket, these can be defined like this: (define true (lambda (t) (lambda (f) t))) (define false (lambda (t) (lambda (f) f))) -(8). Define a "neg" operator that negates "true" and "false". -Expected behavior: (((neg true) 10) 20) evaluates to 20, -(((neg false) 10) 20) evaluates to 10. +* Define a "neg" operator that negates "true" and "false". +Expected behavior: -(9). Define an "and" operator. + (((neg true) 10) 20) -10. Define an "xor" operator. (If you haven't seen this term before, here's a truth table: +evaluates to 20, and + + (((neg false) 10) 20) + +evaluates to 10. + +* Define an "and" operator. + +* Define an "xor" operator. +(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: @@ -50,7 +62,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.)