I’ve explained before that I’m an artist and not a computer scientist, but for those who don’t know I’ve said it again.
There was a time when I was a nuclear engineer for the US Navy as well, but that’s more than half a decade behind me.
I am aware, thanks to wikipedia, that the greek letter lambda is used in some sort of calculus, but I’ve never learned calculus.
I was going through a camera handler script that I found on these forums (posted by Ninth) and I found the following:
self.accept("wheel_up",lambda : self.adjustCamDist(0.9))
And I thought to myself “I haven’t seen this sort of syntax before, a bold faced word followed by colon and a function… and what the duece is lambda?”
So I pose the question to all of you. What the duece is lambda?
The name is a bit misleading.
Basically it’s just shorthand for saying, “I want a function here, but I don’t care for it to be named or owned by anything.”
You could re-write that as:
def yay_wheelUp ():
Oh! How simple. That sounds all but identical to a functor, though there may be differences I don’t know of. I understand exactly what’s happening with that code now, thank you FenrirWolf.
Yeah, I see lambdas used a lot with map/reduce algorithms in Python, so I think it’s a handy stand in.
Someone who’s a bit more familiar with Python could tell you for sure though.
I just thought lambda might be doing some foul Math thing to the values being fed to adjustCamDist.
If I learned anything from being a nuclear engineer, it’s that Math can’t be trusted.