I fully agree with Daphne.

Cons is the CONStructor for the pair type.  Using the name for vectors, strings, etc. confounds sequence-like types with pairs.

However, SRFI 41 reuses the names of cons, car, and cdr for streams.  This confounds a co-inductive type with the inductive type of a pair.  But we already have this confusion with fold/unfold.


Am Do., 29. Juli 2021 um 17:55 Uhr schrieb Daphne Preston-Kendal <xxxxxx@nonceword.org>:
On 29 Jul 2021, at 16:21, Lassi Kortela <xxxxxx@lassi.io> wrote:

> In your opinion:
>
> 1) Is it good style to generalize the word `cons` to cover more types
>   besides linked lists (yielding vector-cons, string-cons,
>   hash-table-cons, etc.)?

Given that cons as verb in colloquial usage has the generalized meaning ‘to allocate memory’, I think defining procedures with these names would be confusing.

> 2) Is `cons-right` a reasonable name for an operation that adds one
>   element to the end of a proper list or other sequence, or does the
>   name amount to an abuse of the concept of consing?

Possibly, but the cons procedure itself is a constructor of pairs, not necessarily of lists. So either it is cons-right!, which mutates its argument, not necessarily a proper list, by recursing into its cdrs and replacing the deepest cdr which is not a pair with a new pair; or it is a procedure whose name possibly starts with list-, which shallow copies its argument to add a new object to the right. But append already exists — the only difference is you have to write (list …) yourself for the new last item. And that’s no less efficient since append won’t copy its last argument.


Daphne