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

List/contains definition unclear #230

Open
littledan opened this issue Dec 8, 2018 · 7 comments
Open

List/contains definition unclear #230

littledan opened this issue Dec 8, 2018 · 7 comments

Comments

@littledan
Copy link

From https://infra.spec.whatwg.org/#list-contain:

A list contains an item if it appears in the list. We can also denote this by saying that, for a list list and an index index, "list[index] exists".

I'm confused about a couple points here:

  • Is the equality algorithm somehow implied by "appears", or is it described somewhere else?
  • How does the second sentence relate to the first?

(Context: I'm wondering about how to use an Infra set for the [[PlatformBrand]] (whatwg/webidl#97), and possibly also for private method brands (tc39/proposal-decorators#180). It looks like I'd use this contains algorithm to check membership, right?)

@annevk
Copy link
Member

annevk commented Dec 10, 2018

See also #106. I think we mostly want object identity here, except for primitive data types. Most specifications already assume those semantics when it comes to equality.

I think the second sentence doesn't really relate to the first that much and probably needs to be reworded. Maybe something like:

For a list list and an index index, list[index] exists, if index is not out-of-bound for list.

@annevk
Copy link
Member

annevk commented Dec 10, 2018

(I'd expect [[PlatformBrand]] to be a set, but yeah, you'd use contains.)

@littledan
Copy link
Author

littledan commented Dec 10, 2018

Can sets contain things like Records? I'm not sure if those are considered to have object identity.

So the second sentence was just an independent definition of "exists"? I don't understand why that's necessary, given the definition of "exists" earlier in the section.

@annevk
Copy link
Member

annevk commented Dec 10, 2018

  1. Sets can contain Records. I'm also not sure how we'd define equality for Records. I guess you need to note your assumptions around that somewhere so we can address it once that's defined.
  2. It's an independent definition of exists, that's needed because typically indexing like that isn't allowed for out-of-bound values.

@littledan
Copy link
Author

  1. Is "appears" interpreted to reference the local definition of "exists"? It's unclear to me how.

@annevk
Copy link
Member

annevk commented Dec 10, 2018

No, I think it's meant as looping over the list, comparing the input item with the items that result from looping, and returning true if they're "equal". Anyway, I agree with you that this could use some refactoring.

@domenic
Copy link
Member

domenic commented Dec 10, 2018

Some definitions in Infra are fairly vacuous. E.g. contains delegates to an undefined "appears in" concept, iterate to "on each item in order", append and prepend to "add". The intention is roughly "you already know what this vague concept is, but here's the exact word you can use and reference".

We could probably redefine "contains" in terms of equals and iterate, instead of "appears". But I'm not sure how far we should pursue such a program. The endpoint of making these definitions rigorous is basically axiomatic set theory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants