On Thu, Jan 19, 2012 at 12:44 AM, Andreas Rossberg <rossb...@google.com>wrote:

> On 19 January 2012 07:51, Mark S. Miller <erig...@google.com> wrote:
> >
> > Because an instance of InfiniteMap conforms to the full Map contract
> (given
> > that baseMap does and is not otherwise used), we have full Liskov
> > substitutability -- you can validly pass an InfiniteMap to an abstraction
> > expecting a Map.
>
> PS: Won't the "full Map contract" eventually contain iterators, too?
> An infinite map cannot sensibly support those.
>
>
Depends what you mean by "sensibly". I see nothing at
http://wiki.ecmascript.org/doku.php?id=harmony:iterators that implies that
iterators must or even should terminate. And infinite iterators (in general
though not here) are clearly useful.

However, I agree that doing an infinite iteration over an InfiniteMap is
unlikely to be useful. For example, the contract can almost be trivially
and uselessly satisfied by having the InfiniteMap return the following
"items" (key-value pair) iterator:

    { next: function() { return [{}, lazyFactory()]; } }

Since each of these keys are fresh, we know we don't need to consult the
baseMap for an overriding mapping. Since there are an infinite number of
such keys, we know they'll never run out, so we can indefinitely postpone
ever needing to return a meaningful mapping. However the "almost" qualifier
above is because, to be correct, the iterator would have to store the new
useless associations in the baseMap before returning them -- making this
technique even more useless.

Infinities are indeed weird.

-- 
    Cheers,
    --MarkM
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to