-
-
Notifications
You must be signed in to change notification settings - Fork 680
Add get-failure-result
to racket/function
#4854
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
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.
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 error message is based on the one produced by failure-result/c
, which is really just the error message produced by (-> any)
. I’m happy to change it, if desired, but consistency with failure-result/c
seemed logical.
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 |
460e74b
to
4993cdd
Compare
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
.