Immutably updating objects Vladimir Nikishkin (31 Oct 2022 01:36 UTC)
Re: Immutably updating objects Arthur A. Gleckler (31 Oct 2022 03:57 UTC)
Re: Immutably updating objects Marc Nieper-Wißkirchen (31 Oct 2022 10:08 UTC)
Re: Immutably updating objects siiky (31 Oct 2022 10:18 UTC)
Re: Immutably updating objects Marc Nieper-Wißkirchen (31 Oct 2022 10:53 UTC)
Re: Immutably updating objects Vladimir Nikishkin (31 Oct 2022 12:54 UTC)
Re: Immutably updating objects Marc Nieper-Wißkirchen (31 Oct 2022 13:09 UTC)
Re: Immutably updating objects Vladimir Nikishkin (03 Nov 2022 02:12 UTC)
Re: Immutably updating objects Marc Nieper-Wißkirchen (03 Nov 2022 07:13 UTC)
Re: Immutably updating objects Vladimir Nikishkin (03 Nov 2022 08:56 UTC)
Re: Immutably updating objects Marc Nieper-Wißkirchen (03 Nov 2022 13:17 UTC)

Re: Immutably updating objects Marc Nieper-Wißkirchen 31 Oct 2022 10:53 UTC

Am Mo., 31. Okt. 2022 um 11:18 Uhr schrieb siiky <xxxxxx@net-c.cat>:
>
> If I understood correctly, I believe the CHICKEN egg typed-records[0]
> has just that feature.
>
> (defstruct foo x y z)
>
> This defines a type `foo` with fields `x`, `y` & `z`. Other than the
> constructor, getters, and setters, it creates also an `update-foo` that
> works like this:
>
> (let* ((foo (make-foo x: 1 y: 2 z: 3))
>        (foo (update-foo foo x: 4)))
>   (foo-x foo)) ;=> 4

This is easy to define (in some form syntactically supported by
standard Scheme); however, it is not a general approach for general
record types because it is not type-safe (in the sense of invariants
that may not be preserved).

Conceptually, there is a subclass of all record types, namely those
that basically model a set of independent fields given a type; for
these, the Chicken approach makes sense.