Email list hosting service & mailing list manager

Generalizing cons, and is cons-right conceptually sound? Lassi Kortela (29 Jul 2021 14:21 UTC)
Re: Generalizing cons, and is cons-right conceptually sound? Daphne Preston-Kendal (29 Jul 2021 15:54 UTC)
Re: Generalizing cons, and is cons-right conceptually sound? Marc Nieper-Wi├čkirchen (29 Jul 2021 16:05 UTC)

Re: Generalizing cons, and is cons-right conceptually sound? Daphne Preston-Kendal 29 Jul 2021 15:54 UTC

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