[racket] on the arity of the composition of procedures with different arities

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Nov 9 14:19:56 EST 2012

Eli, if compose is 20x slower than writing out the lambda, 
and respect for arity costs 5%, I think we're fine. 

A warning in the docs sounds good. Something like 

"Warning: Using compose, instead of plain lambda, for function composition helps readability and facilitates re-coding the numerous point-free examples that appear in the literature on functional programming." 

[I honestly don't see another use.]



On Nov 9, 2012, at 11:40 AM, Eli Barzilay wrote:

> I just measured the overhead again, to see if things changed.  The
> attached file has the exact implementation of the compose functions,
> and another copy with the proper reduction and renaming.  For the
> correct function I'm getting ~5x slowdown from the current code, which
> in turn is 20x slower than just using a lambda.  This is big enough to
> justify a comment saying something like "don't use this if you care
> about speed", which kind of makes the whole point of the function
> redundant.
> 
> Notes:
> 
> 1. Yes, the docs should say that already, but still I consider jumping
>   to a slowdown of two orders of magnitude as a major problem.
> 
> 2. I'm not talking about a theoretical point here -- I *have* seen
>   `compose' used in tight loops, and I have personally written
>   explicit lambdas in code where I really should have just used it.
> 
> 3. There are definitely other cases where things like `apply' are used
>   in a way that doesn't preserve arity, so it's not like this is an
>   exceptional problem (or a new one).
> 
> 4. I'll shut up now.
> 
> 
> 20 minutes ago, Robby Findler wrote:
>> I think the right approach is to make the function behave correctly
>> first and then find the places to optimize second.
>> 
>> In this case, using procedure-reduce-arity (or something else with
>> the same effect) is not merely "nice" but, IMO, necessary. That is,
>> we have procedure-arity in our PL and our primitives/core libraries
>> should respect that.
> 
> 
> -- 
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!
> <x.rkt>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20121109/e3dcc6b6/attachment.p7s>

Posted on the users mailing list.