(no commit message)
[lambda.git] / lambda_evaluator.mdwn
1 Lambda Evaluator
2 ----------------
3
4 There is now a [lambda evaluator](http://lambda.jimpryor.net/lambda-let.html) available.
5 It will allow you to write lambda terms and evaluate them, with full ability to inspect the results.
6 (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.)  
7
8 *Lambda terms*: lambda terms are written with a backslash, thus: `((\x (\y x)) z)`.  
9 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)`.
10
11 *Let*: in order to make building a more elaborate set of terms easier, it is possible to define values using `let`.
12 In this toy system, `let`s should only be used at the beginning of a file.  If we have, for intance,
13
14     let true = (\x (\y x)) in
15     let false = (\x (\y y)) in
16     ((true yes) no)
17
18 the result is `yes`.  Things to watch out for: the expression after the equal sign must have balanced parentheses,
19 and the "in" is obligatory.  If you violate these rules, the system will still produce a result, but it won't make much sense.
20
21 *Abbreviations*: No abbreviations work.  So `\xy.yxx` must be written `(\x (\y ((y x) x)))`. 
22
23 *Comments*: anything following a semicolon to the end of the line is ignored.
24 Blank lines are fine.
25
26 Under the hood
27 ---------------
28
29 The interpreter is written in JavaScript (which is not closely related to Java), and runs inside your browser.
30 So if you decide to reduce a term that does not terminate (such as `((\x (x x)) (\x (x x)))`), it will be your 
31 browser that stops responding, not the wiki server.
32
33 You can inspect the code [here](http://lambda.jimpryor.net/code/lambda.js).  Suggestions for improvements welcome.
34
35 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`.
36
37