

These headaches started appearing in math proofs in the 19th century,Īnd they were causing false results to be proved. The name clash between the two definitions of x confuse us. y + x) to f and do the subsequent substitutions ? We can analyze the situation with lambda-notation:ĭo you bind 5 to x and do the subsequent substitutions ? Procedure call and see where the two x's get declared. How might we explain these two outputs? (Hint: use copy-rule semantics of What should print - 6 or 8? In C and Python, it's 8, but in Lisp, it's 6. Here is a programming example of a name clash:ĭef f(y): return y + x end // what is the value of x here? 3? 5?ĭef g(x): return f(x) end // oops - another x, and it's sent to f. He was interested in studying name clashes. The lambda calculus was invented by Alonzo Church, a mathemetician-philosopherĪt Princeton. Objects as both data and operators (that can be sent messages). The lambda-calculus was the inspiration for Smalltalk, which treated all If E1 then E2 else E3, is really just E1 used as the operator: (E1 E2 E3). The truth values are selector functions, and a standard if-then-else command, We think of the two booleans as data values, but both can be used as operators:Į.g., ( E2 E3) =>* E2 and ([False} E2 E3) =>* E3. Look again at the codings that were proposed earlier for the values, Operator and E2 (and E3, etc.) are the arguments. IMPORTANT: every phrase written in the lambda calculus can be used asĪn operator and also as an argument. There are two other rewriting rules but they are less important to us:Īlpha: (lam I. The beta-rule to the expression does not affect the final answer.īut some expressions have no normal form, which we see later. Normal form, then the normal form is unique - the order in which we apply It takes a lot of work to prove, but if an expression can be reduced to a It can be simplified with the beta-rule.Īn expression that has no redexes is in normal form - it is an "answer".īut we can apply the beta-rule to reduce it to its normal form:
#Lambda calculus boolean free#
I is free in (E1 E2) iff I is free in E1 or I is free in E2Īn expression that has form, ((lam I. The notion of "free in" can be defined equally precisely: If I != J, J is free in E, and K is fresh Where E1 is defined precisely on the syntax of E1 as follows: The primary rewriting rule one uses to "compute upon" a lambda-expression (But the best way to write a lambda-expression is to draw its parse tree!) The outermost parens are also often dropped.

En).Īnother standard abbreviation is to simplify It is standard to eliminate unneeded parens by writing a nestedĪpplication of form (.((E1 E2) E3). Where IDEN is any string-based identifier, e.g., 'x' or 'y' Here is the syntax of the Lambda Calculus - there are identifiers,ĮXPR ::= IDEN | ( lam IDEN. We will have lots more to say about all this.

Why these codings are sensible will be soon seen.Īddition, multiplication, all of arithmetic can be defined on the above codings Įven repetition can be coded in lambda calculus, Incredibly, the above codings can even do away with booleans and ints, replacing them This is a critical insight from modelling with lambda-notation: the order in which you do subsititution does not matter - the final result is always the same.īy the way, the original example at the beginning of this chapter:įunction f requires the "current value" of "global variable" x. We can compute the above program inside-out or outside-in The traditional ordering of assignments is mostly an This is because of the beta-rule for binding of argument to parameter: Lisp programmers quickly discover that assignments are unnecessary, e.g., Shortcut for lambda, but most textbooks use the Greek letter, λ.) y + x) is called a lambda abstraction or anĪbstraction for short. Integer values don't need names why should functions? You can also write a function call with an unnamed function: There is a traditional notation for function-values: The rhs of f = is evaluated to a closure.

Many modern programming techniques stem from the lambda calculus,Ī notational system that was invented around 1920.ġ0.1 Motivation: assignment is unnecessary Copyright © 2010 David Schmidt Chapter 10:ġ0.1 Motivation: assignment is unnecessary 10.2 Lambda Calculus made precise 10.2.1 Name clashes and paradoxes 10.2.2 Exercises 10.3 Encoding arithmetic in lambda calculus 10.4 While-language translated into lambda-calculus 10.4.1 Exercises
