On Fri, Jun 4, 2021 at 6:21 PM flirora wrote:
> Is there a way to define a struct so that it has a field whose value is
> filled in (instead of passed to the constructor) with a value derived from
> other fields? For example, could you define a struct foo with two
> explicit fields, x and y,
I think you can create a custom accessor, and use macros to avoid the Royal
Pain.
One question is, is the derived field expensive to compute? If not, your
custom accessor can just compute the output every time it’s called. But if
it’s expensive, you can use memoization. Both approaches have the
Is there a way to define a struct so that it has a field whose value is
filled in (instead of passed to the constructor) with a value derived from
other fields? For example, could you define a struct foo with two explicit
fields, x and y, plus a field called z whose value is computed as (+ x y)
3 matches
Mail list logo