Lambda is a very powerful function used to make functions. Most of the time you are going to use it in globals to make global functions.
Here is the basic format of lambda
(lambda argumentList function)
the function is not run until the lambda is run and it is supplied the arguments from the argument list.
ie (in globals)
(setq myFunction (lambda (a b) multiply a b))
and now you can use myFunction just as you would use any other function. like (myFunction 3 5) will return 15
You can also pass (in or back) lambda functions and use temporary variables to store them. To use them then you have to use apply.
lets say you where passed in a function called passedFunction and it took two arguments and returned them subtracted
an example of use would be (apply passedFunction (list 9 3)) and that would return 6.
So what cool can you do with all of this?
One thing you can do is store alot of functions in a global list and have a set of items that would use one at random (saving the index of the one that they are using)
That way you have items doing random things from game to game.
one issue is that you can not currently as of .99c store lambda functions in objects. see here
Fun with lambda
- Betelgeuse
- Fleet Officer
- Posts: 1920
- Joined: Sun Mar 05, 2006 6:31 am
Crying is not a proper retort!