kriskowal / gtor

A General Theory of Reactivity
MIT License
3.03k stars 109 forks source link

Indices are a distraction #1

Closed domenic closed 10 years ago

domenic commented 10 years ago

The narrative seems to be something like: "we have an existing iteration interface, { done, value }. This is missing index, so let's add it." But index never plays a role in any of the subsequent work and seems entirely useless; it's just an extra piece of information to be passed around. It definitely doesn't seem to be a fundamental part of the iteration interface on the same level as done and value.

kriskowal commented 10 years ago

Certainly is a distraction, not fundamental to anything so far written. I still need to write more about how index goes from being a position in space to a moment in time for signals and behaviors. Behaviors in particular benefit from being able to map a time to a value.

domenic commented 10 years ago

Right, that was the other thing. They appear as time in one signal example, but the time also seems redundant: you could just do Date.now(), since it is a signal, and there is no (or minimal) delay between the signal production and the callback being called.

kriskowal commented 10 years ago

For sensitive systems of behaviors, particularly in animation, every aspect of the system should be rendered based on a single snapshot of time. Consider an animation of an engine, piston, crankshaft, drive train.

domenic commented 10 years ago

OK, but in that case I would just bundle it into the value, and not make it a fundamental part of the protocol.

kriskowal commented 10 years ago

I am going to heed your words and minimize the discussion of index because it is a tangent. However, I do think it is worth embedding in the protocol itself. Another reason is that it is necessary to faithfully produce this equivalence:

array.forEach(function (value, index) {
    // ...
});
array.iterate().forEach(function (value, index) {
    // ...
})
domenic commented 10 years ago

I guess I don't really see that equivalence as very useful. If you move to iteration, you no longer get indices. Indices seem, at least intuitively, tied to the nature of arrays as random-access data structures; they don't make as much sense to me for iterables, even if in theory they could be added.

I wonder if any other languages' iterable/enumerable implementations include index in the protocol.

kriskowal commented 10 years ago

I wonder if any other languages' iterable/enumerable implementations include index in the protocol.

Not to my knowledge.