Fuzzy wrote:
Ah! Its almost like a macro. I get it now. The % is a place holder. In PLT scheme I can specify a variable.
(lambda (something) (+ 5 something))
I think so, I'm not sure the exact syntax of PLT scheme, % comes from clojure where its just syntactic sugar for the above.
Fuzzy wrote:
But in the case of lisp, I dont need to give it a name. Its useful for a one shot function perhaps.
Yes, you get a lot of one shot functions in lisp if your useing it right. Take this java code:
for (int i=0; i < array.length; i++){
array[i] = array[i] + 5;
}
you've probably written something like this 100 times, only the second line and the name of the array changes, so the lisp guys have distilled it down to its purest form: one function, two arguments: the name of the list and what you want to do to each cell:
(map plusfive list)
of course that means plusfive has to be a prewritten function somewhere, so much easier to use an annonimous function instead
(map (lambda (+ 5 %)) list)
And of course there's probably nice syntactic sugar for that, I don't know PLT scheme but in clojure it looks like this
(map #(+ 5 %) list)