Skip to main content
gamedev.net
🔒 Locked

Lambda calculus

Started by Lode 5 replies 1.5k views
Original Post
Lode
Lode
I've read the Wikipedia article about Lambda calculus several times, I know that boost provides a lambda calculus extension to C++, and that programming languages like Haskell use it. How, though, can something as abstract as lambda calculus be useful to program in? The concept appears so abstract to me that I fail to see how to use it. Has anyone actually used it for programming?
bubu LV
bubu LV
Python uses lambda everywhere.
For example, to add two list (arrays of integers) elements together:
[source lang="python]x = [1, 2, 3]y = [5, 8, 4]z = map(lambda a,b: a+b, x, y)print z  # z will now be [6, 10, 7] 


Also &#106avascript uses clousures (almost same as lambda), to implement various things:
var a = document.createElement("a");a.onclick = function() { alert("you clicked on me!"); }someElement.appendChild(a);
Rebooted
Rebooted
Lambda calculi themselves are very useful for theoretical/research purposes. They provide a basis for other languages and are useful for designing things like type systems and when defining formal semantics. They are not intended to be used as production languages.

The 'lambda' feature seen in python and boost.lambda derives from lambda calculus in which functions are first class and everything is defined in terms of functions ("lambda abstractions").
grhodes_at_work
grhodes_at_work
So, then, one wouldn't use Lambda calculus for game development.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
ToohrVyk
ToohrVyk
Quote:
Original post by Lode
How, though, can something as abstract as lambda calculus be useful to program in? The concept appears so abstract to me that I fail to see how to use it.


It is not useful to program in. The first and foremost use of lambda calculus is being a language in which it is easy to prove things. It does not, however, have the nifty things we are accustomed to in programming languages, such as integers, conditionals or loops, although these can of course be emulated using the language. Other features (such as binding to libraries) are completely missing. Lambda calculus is a language that computes, not a language that does things.

The fundamental principle of lambda calculus, however, is extremely powerful: any function (lambda abstraction) can be used like any other object. The expressiveness of this is excellent, and shortens the code in many situations.
Daerax
Daerax
Actually you can technically program in a Lambda calculus if you extend it with rich types, provide a spoonfull of syntatic sugar and specify some kind of evaluation methodology. Thus anyone who is programming in Haskell or functionally in Lisp or some kind of ML is in fact actually effectively programming *in a* lambda calculus. As stated, the important notion of first class functions and other powerful abstractions and in essence being extensions to a lambda calculus allow these languages to benefit from its (the lambda calculus) powerful ability in abstraction, allowing for these languages to be extremely succint in implementing powerful and general algorithims. Especially in those area which have to do with large data manipulation and matching and as well concepts which lend themselves well to recursionl.

Quote:
Original post by grhodes_at_work
So, then, one wouldn't use Lambda calculus for game development.


One way to use the lambda calculus for game development would be for example in the more mathematical or abstract aspects. One way would be to implement the specifications of some data structure (graph, number system,...) or set of algorithims and then proving its soundness. Such a path would be highly more efficient that the standard write and debug C++ code with completely eliminated syntatical errors and significantly reduced chances for a logical one.

[EDIT]To clarify, this method would also be much shorter in terms of time spent implementing due to the increased expressiveness of the typed lambda calculus. You could then extract a fair program (as yet generated code is not too clean so you often have to perform minor modifications with respect to efficiency by hand) from the proof.

[Edited by - Daerax on September 27, 2006 9:05:35 AM]
pTymN
pTymN
I am writing a 2D physics engine in Corman Common Lisp. The latest release brings the double precision floating point operations up to the same speed as C++. I am seeing about a 10% decrease in speed using Lisp, but I have gained about 5000% performance gains over the C++ version with optimizations that would have been tricky at best to figure out how to do with C++ containers. The ability to easily assemble temporary queues and ordered sets has allowed me to quickly iterate through many caching schemes to find what works for my problem space.

I'm enjoying the ease with which code can be compressed, say by checking the value of a boolean and passing '+ or '- to a block of code that is large and nearly identical except for that one detail. You really do gain readability when you can easily compress code that conforms to patterns.

Another use of being able to easily create and pass anonymous functions around is that you can define behaviors for your game objects often in the same places that you initialize other data. This also helps readability.


Here's code from a game I am writing in actionscript:

var bumper:LineSurface = new LineSurface(100, 100, 300, 100);
engine.addSurface(bumper);
bumper.onContact = function () {
pinball.velocity.plus(bumper.faceNormal);
}


The function is not stuffed away in some pinball class! I don't even have to scroll through the file to find the function, its right there to look at. That's sweet!
 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.