whatwg / infra

Infra Standard
https://infra.spec.whatwg.org/
Other
118 stars 95 forks source link

List/contains definition unclear #230

Open littledan opened 5 years ago

littledan commented 5 years ago

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:

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

annevk commented 5 years ago

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 commented 5 years ago

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

littledan commented 5 years ago

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 commented 5 years ago
  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 commented 5 years ago
  1. Is "appears" interpreted to reference the local definition of "exists"? It's unclear to me how.
annevk commented 5 years ago

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 commented 5 years ago

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.