-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add data type guards #513
Open
eutro
wants to merge
6
commits into
jackfirth:master
Choose a base branch
from
eutro:data-type-guards
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add data type guards #513
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ff8e798
Add #:guard-maker for wrapper types
eutro a55f3e5
Update contract in docs
eutro ea8b1ad
Add #:guard-maker for tuple types
eutro 7f94173
Merge wrapper-guards
eutro 640584f
Update wrapper guards to be in terms of tuple guards
eutro b5cd27f
Add #:guard-maker for record types
eutro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,12 +58,15 @@ obvious order to those pieces. | |
(code:line #:accessor-name accessor-id) | ||
(code:line #:pattern-name pattern-id) | ||
(code:line #:property-maker prop-maker-expr) | ||
(code:line #:guard-maker guard-maker-expr) | ||
(code:line #:inspector inspector-expr)]) | ||
|
||
#:contracts | ||
([prop-maker-expr | ||
(-> uninitialized-record-descriptor? | ||
(listof (cons/c struct-type-property? any/c)))] | ||
[guard-maker-expr | ||
(or/c #f (-> uninitialized-record-descriptor? procedure?))] | ||
[inspector-expr inspector?])]{ | ||
Creates a new @tech{record type} named @racket[id] and binds the following | ||
identifiers: | ||
|
@@ -103,12 +106,12 @@ obvious order to those pieces. | |
@racket[constructor-id] when used as an expression. Use | ||
@racket[#:omit-root-binding] when you want control over what @racket[id] is | ||
bound to, such as when creating a smart constructor. | ||
|
||
The @racket[prop-maker-expr] is used to add structure type properties to the | ||
created type, and @racket[inspector-expr] is used to determine the | ||
@tech/reference{inspector} that will control the created type. See | ||
@racket[make-record-implementation] for more information about these | ||
parameters. | ||
created type, @racket[guard-maker-expr] is used to create the guard procedure, and | ||
@racket[inspector-expr] is used to determine the @tech/reference{inspector} that | ||
will control the created type. See @racket[make-record-implementation] for more | ||
information about these parameters. | ||
|
||
@(examples | ||
#:eval (make-evaluator) #:once | ||
|
@@ -208,17 +211,44 @@ can access any field in the record: the per-field accessors created by | |
[#:property-maker prop-maker | ||
(-> uninitialized-record-descriptor? | ||
(listof (cons/c struct-type-property? any/c))) | ||
default-record-properties]) | ||
default-record-properties] | ||
[#:guard-maker guard-maker | ||
(or/c #f (-> uninitialized-record-descriptor? procedure?)) | ||
#f]) | ||
initialized-record-descriptor?]{ | ||
Implements @racket[type] and returns a @tech{type descriptor} for the new | ||
implementation. The @racket[inspector] argument behaves the same as in | ||
implementation. | ||
|
||
The @racket[inspector] argument behaves the same as in | ||
@racket[make-struct-type], although there are no transparent or prefab record | ||
types. The @racket[prop-maker] argument is similar to the corresponding | ||
argument of @racket[make-struct-implementation]. By default, record types are | ||
types. | ||
|
||
The @racket[prop-maker] argument is similar to the corresponding | ||
argument of @racket[make-struct-implementation]. | ||
|
||
The @racket[guard-maker] argument is a procedure that should accept the partially | ||
constructed record descriptor, and must return a guard procedure. This guard | ||
procedure is similar to the one in @racket[make-struct-type]. It will accept | ||
all the arguments to the record constructor as positional arguments, | ||
sorted alphabetically by field name, and the values it returns will be the | ||
values stored in the record. | ||
|
||
By default, record types are | ||
created with properties that make them print like transparent structures, | ||
except field names are included --- see @racket[default-record-properties] for | ||
details.} | ||
|
||
@defform[(record-guard-maker/c keyword-contract-pair ...) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unintentional blank? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not unintentional but maybe unnecessary. |
||
#:grammar | ||
([keyword-contract-pair | ||
(code:line field-name-keyword field-contract)])]{ | ||
Returns a procedure suitable to be passed as the | ||
@racket[#:guard-maker] argument to @racket[make-record-implementation] | ||
or @racket[define-record-type]. The guard procedure will ensure that | ||
the fields of the record are protected by their corresponding @racket[field-contract]s. | ||
This is analogous to @racket[struct-guard/c].} | ||
|
||
@defproc[(record-descriptor-type [descriptor record-descriptor?]) record-type?]{ | ||
Returns the @tech{record type} that @racket[descriptor] implements.} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This might just be an artifact of a rewrap, but this line seems to end too soon.