
Invoking (lambda (x) (+ x 1)) on the argument 3 would look like this: To invoke an anonymous function, we simply invoke it like any other function.
#Slow motion fotomagico plus#
In this case, the returned result will be the argument plus one, and the argument will not be side effected. For instance, (lambda (x) (+ x 1)) is a function that takes in an evaluated argument, binds it with x, and then computes the body of the lambda form with the understanding that any occurrence of parameter x in the body will refer to the value of x bound by the lambda form. This is done via lambda, the anonymous function. The next thing we need is a way to abstract out common process patterns into descriptions. zero? is a function (called a predicate) that is used to determine whether a number is 0 or not. If is true, is evaluated and returned, otherwise is evaluated and returned. Let me motivate an example of that by first showing the if function (which in LISP is a true function). Note: In the Scheme dialect of LISP, the function position is treated precisely the same as the argument positions. The one round of evaluation can be used to invoke a function call from any position:īecause a list in any position can have a function position and argument positions of its own, and so on, to arbitrary depth. Specifically, the function position gets evaluated, then each argument position gets evaluated, then, the evaluated function gets applied to the evaluated arguments. Note that with this style of syntax, it is easy to represent + with an arbitrary numbers of arguments: (+ 1 2 3 4 5).įurther, lets say that every top level position of a list gets one round of evaluation.

Lets stick to this syntax for everything, lest the syntax get so unwieldy that parsing become a science in and of itself. This form of prefix notation is the chosen syntax of LISP. Lets tuck sin into the list of arguments and use spaces instead of commas if there is more than one argument: (sin 3). Lets pick the sine function as it would look if applied to the numerical argument 3: sin(3). Lets start with a some arbitrary function and convert it from how youd see it in a math book or C program to how it would look in LISP. (This will be just enough to make you dangerous.) What follows will be a crash course in LISP. l is the anonymous function in l-calculus, and lambda is the anonymous function in LISP. l-calculus preceded LISP and LISP drew from it to some extent.

L-calculus is a calculus which expresses computation via anonymous functions.
#Slow motion fotomagico code#
An attempt will then be made to use l-calculus as a programming language in its own right to code a popular function in an effort to show the clean, algebraic-like properties of l-calculus and to consider (in a small way) if l-calculus might serve as a light unto the footsteps to guide the way to computing without gratuitous complexity. This article will introduce l-calculus and combinators, and show some similarity between l-calculus and the programming language LISP. It has no concept of Turing machine style state, and it has some very nice algebraic-like properties. There is however, another model, equally as powerful, that is quite different. If something is computable on a Turing machine, it is considered computable if something isnt computable on a Turing machine its considered uncomputable. Most people have heard of the Turing machine, as its now tantamount to being the measuring stick by which computability is judged. Wouldnt it be nice to be able to manipulate computer code in the same sort of clean mathematical way that one does algebra? Usually computer code is too ad hoc to allow much of that, but what if we had a super clean model that we could work with? Even if such a model wasnt practical, it would certainly still be interesting, and what could be found out from it might be mappable back into computer languages which dont have as neat a set of algebraic-like properties. Such tutorialness should not be taken as an insult to anyones intelligence. Note to the Überprogrammer and disclaimer: I will be endeavoring to write so simply that everyone should be able to get something out of this article. People who like this sort of thing will find that this is the sort of thing they like. Abe Lincoln

∺ Calculus for the Algebraic-like Manipulation of Computer Code, or Why Oh Why Oh Y? Lambda Calculus Volume Number: 7 Issue Number: 5 Column Tag: Lisp Listenerīy André van Meulebrouck, Chatsworth, CA\ Educational Institution and Student Discounts.
