On Fri, Oct 15, 2010 at 11:39:01PM -0400, Aleksandar Matijaca wrote:
Hi there,
a quick question - I have a reasonably firm understanding of how lambda functions work
You mean just "functions", or if it's not the anonymous aspect that you're emphasizing, "closures". You wouldn't emphasize "literal strings", or "unnamed strings", would you?
, however, I cannot immediately see why you would want to use one, when you can write a perfectly good NAMED function instead...
I don't know why you would want to pass an unnamed string, e.g.:
f(s + "\n") // Java, Python (f (string-append s "\n")) ; Scheme
when you could write a perfectly good NAMED string instead:
String s1 = s + "\n" // Java, Python (drop "String") f(s1)
(let ((s1 (string-append s "\n"))) (f s1))
Once you understand that, maybe part of your question is, when would one ever pass a function? If you know any object orientation, the same question is: when would one ever pass an object having a method?
And after that, when would one ever have a function not known before running the program, i.e. produced dynamically (e.g. the way the string s + "\n" is produced dynamically). In OO: why would one make objects with state only known when running the program (and an unknown number of ojects, so they can't even all be named beforehand). Make sure you understand that lambda produces a *closure*, not just a "regular" function.
Others will presumably give examples, but the above questions let you leverage and connect your understanding of other parts of programming, to "lambda"s.
So under which circumstances would you absolutely want to use a lambda function and why, and under which circumstances would you absolutely NOT want to use a lambda function..
Thanks, Alex.
toronto-lisp mailing list toronto-lisp@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/toronto-lisp