-
-
Notifications
You must be signed in to change notification settings - Fork 648
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 get-failure-result
to racket/function
#4854
base: master
Are you sure you want to change the base?
Conversation
(if (procedure-arity-includes? v 0) | ||
(v) | ||
(raise-argument-error 'get-failure-result | ||
"a procedure that accepts 0 non-keyword arguments" |
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 should use (procedure-arity-includes/c 0)
as the contract string, I think.
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 intent here may have been to match the exception raised by hash-ref
. It needs to different, though, to do that. The hash-ref
function conceptually always applies a procedure failure result to 0 arguments, but it improves the exn:fail:contract:arity
error message.
If @racket[v] is a procedure, it is applied in @tech{tail position} to zero | ||
arguments to produce a result. Otherwise, @racket[v] is returned. | ||
|
||
@racket[get-failure-result] can be used to extract the value of failure result |
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.
Nit: should be "The get-failure-result
function" to avoid starting a sentence with a lowercase identifier (per the style guide).
I have also written this function multiple times, but I think I have rarely if ever implemented an explicit arity check. That seems quite useful for cases when the argument isn't already protected by |
This adds a very simple function named
get-failure-result
toracket/function
. It is essentially justexcept that the version in this PR also includes an explicit arity check.
Since this function is so simple, the convenience it affords is obviously extremely minor. Still, I’ve written it so many times that it feels worth putting somewhere, especially since we already have
failure-result/c
.