[plt-scheme] How to apply a multi-argument function to each element of a list
On Mar 2, 2010, at 8:45 PM, Barry Brown wrote:
> On Mar 2, 2010, at 5:19 PM, Matthias Felleisen wrote:
>
>> 1. Use #lang scheme instead of damn-big-language.
>>
> I see this over and over on the mailing list. I must not have been paying attention when the usage became common. What advantage does "#lang scheme" have over selecting the language from the Language menu?
Look for 'Module' in the language dialogue. A module starts with
#lang
followed by the language you wish to use. In your case, use scheme. (One day, try lazy.)
>> 2. I also recommend this pattern:
>>
>> (define (encrypt n m)
>> (local ((define (encrypt-message msg) ... msg ... n ... m ...))
>> encrypt-message))
>>
>> (map (encrypt 17 30) (make-list 100000))
>
> The tradeoff here is explaining the "local" syntax instead of the "curry" concept. I'll have to think about which would be more appropriate, since the students have seen neither.
A local definite is like a regular define except that the name is visible only from opening ( to closing ). That's it. In many cases, you can go back and forth between local and global definitions with copy-and-paste.
The novel concept is that a function (name) doesn't have to appear to the right of ( and thus becomes a value in its own right. I switched from lambda to this way of introducing 1st-class functions when I realized that kids like naming things.
-- Matthias