anything
2021-2-11 19:13:41

Can I specify different #:auto-value to different optional fields? Why not? (struct transaction (nonce gas-price gas-units-max to amount data [v #:auto] [r #:auto] [s #:auto]) #:auto-value 0 #:transparent)


samth
2021-2-11 19:19:42

No, you can’t. Also that structure is not useful, because all of the auto fields would be permanently 0. #:auto is only possibly useful with mutable fields, and is in reality never useful.


anything
2021-2-11 19:37:39

What would you do if you wanted to fill out an aggregate value little by little? There are certain required fields to fill out at first, but others that you may fill out later or may never fill out? How do Racketeers handle this?


samth
2021-2-11 19:41:08

What do you mean “fill out little by little”? Do you mean, start with a structure with some default values and later update that structure instance with new data? In that case, mutation is maybe the right approach. Or do you mean “create a structure where right now it has mostly default values, but later I’ll change the program to specify more”? In that case, I would just write a smart constructor function. There are some packages that generate such functions automatically, using keywords — I think struct++ is a nice option here.


anything
2021-2-11 19:45:05

I meant the second option. So the idea seems to be to specify a rigid structure (that’s always completely “filled out” [if I may these terms) and use a smart constructor to deal with all my user-needs. Perhaps I could use a constructor that instead of mutating fields, it would actually produce a new value with the changes I’d like. Perhaps this is a case of not encouraging mutation?

Because, yes, my habit is telling me overwrite data, so I would have to use #:mutable there too — and had not even realized it yet.

Thanks for your assistance! I’ll look into struct++ too. Thank you!


samth
2021-2-11 19:45:47

The issue with #:auto is just that it’s very old and not useful.


kellysmith12.21
2021-2-12 04:31:18

Maybe the docs should describe #:auto struct fields as deprecated?


laurent.orseau
2021-2-12 07:42:46

struct are in desperate need of an overhaul, but its so deep in the language that this will likely have to wait for racket 2


notjack
2021-2-12 07:44:06

I think it would be possible to do it without waiting for racket2


notjack
2021-2-12 07:45:17

we would just have to stop calling them structs and start calling them something else (and provide automated migration tools :wink:)