From 6c1124e2ac83d98a64f1143aaf72a6dc7dc310ee Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Thu, 23 Sep 2010 02:19:35 -0400 Subject: [PATCH] prep for new evaluator Signed-off-by: Jim Pryor --- assignment2.mdwn | 2 +- lambda_evaluator.mdwn | 103 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 96 insertions(+), 9 deletions(-) diff --git a/assignment2.mdwn b/assignment2.mdwn index ff600cc7..3e932561 100644 --- a/assignment2.mdwn +++ b/assignment2.mdwn @@ -1,4 +1,4 @@ -For these assignments, you'll probably want to use a "lambda calculator" to check your work. This accepts any grammatical lambda expression and reduces it to normal form, when possible. See our [lambda-let page](/lambda-let.html), based on Chris Barker's JavaScript lambda calculator and [Oleg Kiselyov's Haskell lambda calculator](http://okmij.org/ftp/Computation/lambda-calc.html#lambda-calculator-haskell). +For these assignments, you'll probably want to use our [[lambda evaluator]] to check your work. This accepts any grammatical lambda expression and reduces it to normal form, when possible. More Lambda Practice diff --git a/lambda_evaluator.mdwn b/lambda_evaluator.mdwn index 31021dce..5734f8ab 100644 --- a/lambda_evaluator.mdwn +++ b/lambda_evaluator.mdwn @@ -2,11 +2,12 @@ Lambda Evaluator ---------------- There is now a [lambda evaluator](http://lambda.jimpryor.net/lambda-let.html) available. -It will allow you to write lambda terms and evaluate them, with full ability to inspect the results. +It will allow you to write lambda terms and evaluate (that is, normalize) them, and inspect the results. (This won't work in Racket, because Racket doesn't even try to represent the internal structure of a function in a human-readable way.) *Lambda terms*: lambda terms are written with a backslash, thus: `((\x (\y x)) z)`. -If you click "Reduce", the system will produce a lambda term that is guaranteed to be reduction equivalent (`<~~>`) with the original term. So `((\x (\y x)) z)` reduces to (a lambda term equivalent to) `(\y z)`. + +If you click "Normalize", the system will try to produce a normal-form lambda expression that your original term reduces to (~~>). So `((\x (\y x)) z)` reduces to `(\y z)`. *Let*: in order to make building a more elaborate set of terms easier, it is possible to define values using `let`. In this toy system, `let`s should only be used at the beginning of a file. If we have, for intance, @@ -15,14 +16,93 @@ In this toy system, `let`s should only be used at the beginning of a file. If w let false = (\x (\y y)) in ((true yes) no) -the result is `yes`. Things to watch out for: the expression after the equal sign must have balanced parentheses, -and the "in" is obligatory. If you violate these rules, the system will still produce a result, but it won't make much sense. - -*Abbreviations*: No abbreviations work. So `\xy.yxx` must be written `(\x (\y ((y x) x)))`. +the result is `yes`. *Comments*: anything following a semicolon to the end of the line is ignored. Blank lines are fine. +*Abbreviations*: In an earlier version, you couldn't use abbreviations. `\x y. y x x` had to be written `(\x (\y ((y x) x)))`. We've upgraded the parser though, so now it should be able to understand any lambda term that you can. + +*Constants*: `true` and `false` are pre-defined to their standard values. So too are the combinators `S`, `K`, `I`, `C`, `B`, `W`, and `T`. Finally, integers will automatically be converted to Church numerals. (`0` is `\s z. z`, `1` is `\s z. s z`, and so on.) + + + + + + + + + + +
+
+ + + + Under the hood --------------- @@ -30,8 +110,15 @@ The interpreter is written in JavaScript (which is not closely related to Java), So if you decide to reduce a term that does not terminate (such as `((\x (x x)) (\x (x x)))`), it will be your browser that stops responding, not the wiki server. -You can inspect the code [here](http://lambda.jimpryor.net/code/lambda.js). Suggestions for improvements welcome. +The main code is [here](http://lambda.jimpryor.net/code/lambda.js). Suggestions for improvements welcome. + +The code is based on: + +* Chris Barker's JavaScript lambda calculator +* [Oleg Kiselyov's Haskell lambda calculator](http://okmij.org/ftp/Computation/lambda-calc.html#lambda-calculator-haskell). +* The top-down JavaScript lexer and parser at . -Improvements we hope to add soon: the ability to reduce Combinatory Logic combinators; the ability to translate from CL to the lambda calculus; and more sensible variable names instead of `g354`. +Improvements we hope to add soon: the ability to reduce Combinatory Logic combinators and report the result as combinators, rather than in lambda forms. +For these assignments, you'll probably want to use a "lambda calculator" to check your work. This accepts any grammatical lambda expression and reduces it to normal form, when possible. See our [lambda-let page](/lambda-let.html), -- 2.11.0