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)
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.
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?
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.
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!
The issue with #:auto
is just that it’s very old and not useful.
Maybe the docs should describe #:auto
struct fields as deprecated?
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
I think it would be possible to do it without waiting for racket2
we would just have to stop calling them structs and start calling them something else (and provide automated migration tools :wink:)