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

From: ifconfig nslookup (nslookupifconfig at hotmail.com)
Date: Wed May 26 18:04:47 EDT 2004

I was about to say the same thing but Outlook crashed and deleted my mail,
and when I was going to write it again I saw Jens's response.

Anyway, it would be sensible for a function that returns the same list
except with a different head to use the common tail, but map goes through
the entire list anyway.

Also, (map identity l) is an easy way to replicate a list, when you need it.


-----Original Message-----
From: plt-scheme-admin at list.cs.brown.edu
[mailto:plt-scheme-admin at list.cs.brown.edu] On Behalf Of Jens Axel S?gaard
Sent: Wednesday, May 26, 2004 10:48 PM
Cc: plt-scheme at list.cs.brown.edu
Subject: Re: [plt-scheme] should `map' reuse cons cells?

  For list-related administrative tasks:

Doug Orleans wrote:
> According to the SRFI-1 notes about its reference implementation:
>   Functions reuse longest common tails from input parameters to
>   construct their results where possible.
> Shouldn't that mean that the following should be true?
>   > (define l (list 1 2 3))
>   > (eq? l (map identity l))
>   #f


The function map have can't determine whether the given function
behaves like the identity on all elements of the list without
first building a list with the mapped elements and then compare
this list to the original.

The note is there to make sure that those functions where one
expects common tails to be reused (e.g. drop) actually
does reuse.

In other words, I interpret the "where possible" not to mean
"theoretically possible" but to mean "possible without speed
or memory sacrifices".

Jens Axel Søgaard

Posted on the users mailing list.