greg
2019-3-30 14:52:31

@michaelmmacleod I’m not familiar with #:super. Is that something new, or, a mistake? I’d just do (struct B A (b))?


greg
2019-3-30 14:57:01

Oh. I guess #:super is one of the many struct options I’ve never need to use and therefore about which I’m ignorant. :smile: Maybe contract-out doesn’t understand how to use the struct-type struct:A supplied with #:super? Understanding why, more thoroughly, would be interesting (for me, someday). But meanwhile I am pretty sure (struct B A (b)) will just work.


greg
2019-3-30 14:59:39

I think 99% of the time I use struct subtypes, at all, is simply to express a kind of “union” or sum type, and you get the predicate for free.


greg
2019-3-30 15:02:33
(struct Message (id))
(struct Request  Message (blah blurp))
(struct Response Message (bleep))

greg
2019-3-30 15:03:07

So now you get Message? and you DRY the id bit. That’s about as fancy as I get with struct subtypes. ¯_(ツ)_/¯


greg
2019-3-30 15:07:42

In that little example, make all the structs #:prefab, and now you have a wire format to write and read. To work out some new system. Later, someday/maybe, if the raw bytes count really matters (sometimes it really doesn’t) then you can use something like bitsyntax.


greg
2019-3-30 15:08:22

Meanwhile you’re not detoured by “premature ceremonialization”.


michaelmmacleod
2019-3-30 18:24:00

@greg Thanks! That’s definitely the problem — using the subtype struct syntax without #:super works. At first approximation #:super and super-id seem to do the same thing. It is a bit strange that #:super doesn’t work with contract-out. Actually, your example is pretty close to what I had in mind: (struct status (id)) (struct working status ()) (struct idle status ()) I’m using them to help manage the state of several places. Using subtype structs is nice because they work with match, ie (match (working 2) [(status id) id])


greg
2019-3-30 18:26:57

Oh wow, @ryanc has a package for ASN.1. I think @tonyg and @ryanc are my top two Racket package heroes for tackling necessary but difficult things really well.


greg
2019-3-30 18:28:50

@michaelmmacleod Yep the situation where most or even all of the sub-structs don’t even add any fields, is something I’ve done, too.


greg
2019-3-30 18:29:31

It’s a nice way to express things.


lexi.lambda
2019-3-30 18:32:48

@michaelmmacleod #:super allows providing an arbitrary supertype dynamically, at runtime. The supertype syntax uses static, compile-time information associated with a particular binding.


lexi.lambda
2019-3-30 18:33:48

You can, for example, write (define (f a) (struct b () #:super a) (b)). You can’t do that with the supertype syntax.


lexi.lambda
2019-3-30 18:33:55

You don’t usually want to use #:super.


michaelmmacleod
2019-3-30 18:39:36

Okay it all makes sense now, thanks! I’ll stick with the super-id syntax, since I’m not doing any run-time struct creation.