Re: [racket-users] Computed properties for a struct?

2021-06-07 Thread David Storrs
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,

Re: [racket-users] Computed properties for a struct?

2021-06-04 Thread Sorawee Porncharoenwase
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

[racket-users] Computed properties for a struct?

2021-06-04 Thread flirora
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)