Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

NoahStoryM
Copy link
Contributor

No description provided.

(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))
Copy link
Collaborator

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)

(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))
Copy link
Collaborator

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))
Copy link
Collaborator

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: '()

@shhyou shhyou added the api design Related to the design of core libraries and language features label Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api design Related to the design of core libraries and language features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants