-
-
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 list-update*
and list-set*
.
#4415
base: master
Are you sure you want to change the base?
Conversation
racket/collects/racket/list.rkt
Outdated
(unless (list? l) | ||
(apply raise-argument-error 'list-update* "list?" 0 l pairs)) | ||
(unless (even? (length pairs)) | ||
(error 'list-update* "expected an even number of association elements, but received an odd number: ~e" pairs)) |
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.
IIUC, we should avoid using error
, since it does not follow the error message conventions.
Here's how this kind of pairing errors are reported in racket/collects/racket/private/hash.rkt
's paired-fold
:
(raise-arguments-error
who
(format "expected ~a, but received ~a"
"an even number of association elements"
"an odd number of association elements")
"association elements"
pairs0)
racket/collects/racket/list.rkt
Outdated
(unless (list? l) | ||
(apply raise-argument-error 'list-set* "list?" 0 l pairs)) | ||
(unless (even? (length pairs)) | ||
(error 'list-set* "expected an even number of association elements, but received an odd number: ~e" pairs)) |
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.
Ditto.
(unless (exact-nonnegative-integer? (car p)) | ||
(apply raise-argument-error 'list-set* "exact-nonnegative-integer?" i l pairs)) | ||
(check (cddr p) (+ 2 i)))) | ||
(define cache (apply hasheq pairs)) |
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 think there must be additional checks that all indices are in bound. Otherwise, you get:
> (list-set* '(1 2 3) 1000 1)
car: contract violation
expected: pair?
given: '()
No description provided.