[racket-dev] Fancy application/automatic anonymous functions

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Tue May 17 15:24:17 EDT 2011

On Tue, May 17, 2011 at 3:20 PM, John Clements
<clements at brinckerhoff.org> wrote:
>
> On May 17, 2011, at 12:14 PM, Sam Tobin-Hochstadt wrote:
>
>> Scala has the nice feature that if you write something like this:
>>  lst.map(_ - 1)
>> It automatically rewrites to a function like this:
>>  lst.map(x => x - 1)
>> This makes writing some higher-order functions much easier.
>>
>> Of course, it's easy to make this using a macro and `#%app'.  You can
>> see the result here:
>>  github.com/samth/fancy-app
>>
>> I'm planning to put this in `unstable/app', and if there's interest
>> I'll think about incorporating it into the default `#%app', after some
>> experience with it.
>>
>> Lots of people have written similar things (`cut' in SRFI 26, Jay's
>> `super-cut', etc), but I'd like to move towards using it implicitly.
>
> Just to clarify (your README is a bit terse ...): this rewrites all applications where one of the terms is the free identifier '_' . Correct me if I'm wrong.

This is very close, but wrong in a very important way: the identifier
`_' is *bound* by `racket/base' (already).  It's treated like a bound
keyword by my `#%app' in the same way `else' is treated by `cond'.

> I think it's vaguely amusing that the wisdom that we've gained in developing sophisticated syntactic tools convinces us 90% of the time not to use them.

I don't know what you mean here.
-- 
sam th
samth at ccs.neu.edu



Posted on the dev mailing list.