-
-
Notifications
You must be signed in to change notification settings - Fork 103
Allow the types created for structs to be specified manually instead of always generating them from the struct name #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow the types created for structs to be specified manually instead of always generating them from the struct name #134
Conversation
I like this idea, but I think it should probably be a new keyword option to |
Sure, that works. Just add |
I like |
@lexi-lambda ping |
b12374f
to
b29edb4
Compare
@samth I updated this to use |
;; FIXME: unsound, but relied on in core libraries | ||
;; #:guard ought to be supportable with some work | ||
;; #:property is harder | ||
(~optional (~seq #:guard guard:expr)) | ||
(~seq #:property prop:expr prop-val:expr)) | ||
...))) | ||
...) | ||
#:attr untyped #`(#,@(if (attribute mutable?) #'(#:mutable) #'()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samth This bit right here is sort of icky. I’d appreciate any tips on how to do this without the brittle repetition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The simplest way would be to use a parameterized splicing syntax class that has the keyword in a list as an attribute, if present, and an empty list otherwise. Also binding it to an attribute of ...
depth 1 would let you write the results as something like:
mutable?.kw ...
transparent?.kw ...
and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure I understand. Could you show me a simple example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just composing this in the text window, but something like this:
(define-splicing-syntax-class (opt-kw kw)
[pattern (~seq k:keyword)
#:when (eq? kw (syntax-e #'k))
#:with (kw ...) #'(k)]
[pattern (~seq)
#:with (kw ...) #'()])
and then
(~var mutable (opt-kw '#:mutable))
Looks good with comments addressed. |
876e2ca
to
81be660
Compare
This allows the types generated by the struct form, as well as #:struct clauses of require/typed, to be specified explicitly using a #:type-name option. This allows the name of a struct and the type it is assigned to be different. Closes racket#261
81be660
to
a3ca5ae
Compare
This change affects all the struct definition forms as well as
#:struct
clauses inrequire/typed
. It's something I've been wanting to change for a while, but I've only now gotten around to doing it. The change is simple and can probably best be explained in code.(struct [point : Point] ([x : Real] [y : Real]))
This creates a struct called
point
, but the type generated for it isPoint
. The change torequire/typed
is the same.Capitalization is, unsurprisingly, the main motivator behind this change, which lets both naming conventions be satisfied without needing any type aliases.