Le Wed, 25 Feb 2009 00:01:49 -0000, "Alan Gauld" <alan.ga...@btinternet.com> s'exprima ainsi:
> > "nathan virgil" <sdragon1...@gmail.com> wrote > > > I'm not familiar with lambdas yet, and I don't think this book will > > introduce me to them; they aren't listed in the index, anyway. > > lambda is just a fancy mathematical name for a simple > concept - its a block of code, like the body of a function. > In Python its even simpler, it is an expression. And we > store that expression and make it callable. > > > def funcname(aParam): > return <expression using aParam> > > is the same as > > funcname = lambda aParam: <expression using aParam> > > In some languages, including some Lisp dialects function > definitions are syntactic sugar for exactly that kind of lambda > assignment. Some even make it explicit as in: > > (define func > ( lambda (aParam) > (expression using aParam))) In io (a wonderful prototype-based languages which syntax reflects the code structure (read: parse tree) like in Lisp), you would have: method_name := method(aParam, <expression using aParam>) for instance: perimeter := method(radius, 2 * PI * radius) average := method(values, sum := values sum sum / values count ) [Above: there is not '.' -- return value needs not be explicit] > In Python its more like the other way around, functions are > defined using def and lambdas are really syntax wrapped > around that. > > lambdas are often offputting to beginners but they are useful > in avoiding lots of small oneliner type functions (and the resultant > namespace clutter) and they are very important in understanding > the theory behind computing (ie. Lambda calculus). > > HTH, > > ------ la vita e estrany _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor