[plt-scheme] should `map' reuse cons cells?

From: Bradd W. Szonye (bradd+plt at szonye.com)
Date: Wed May 26 17:10:52 EDT 2004

On Wed, May 26, 2004 at 05:08:31PM -0400, Doug Orleans wrote:
> Eli Barzilay writes:
>  > On May 26, Doug Orleans wrote:
>  > > Anyway, I think it would be nice for PLT's implementation of `map' to
>  > > reuse longest common tails.  (Or at least PLT's implementation of
>  > > SRFI-1's version of `map'.)  Thoughts?
>  > 
>  > Wouldn't it be healthier to simply add a `map!'?
> 
> SRFI-1 has a `map!', but that's something different: it doesn't just
> reuse cons cells from its input, it mutates them.  I want a functional
> `map', but one that doesn't create new cells for sublists if all the
> elements are `eq?' to the original.  Besides minimizing garbage, it
> would speed up things like `equal?' later on (assuming it uses `eq?'
> to shortcut).

That won't minimize garbage; indeed, it'll /create/ garbage. This MAP
would need to create the results, compare them to the original list, and
then throw them away if they match.
-- 
Bradd W. Szonye
http://www.szonye.com/bradd


Posted on the users mailing list.