agemoagemo / yahoo.com wrote:
> --- Robert Klemme <bob.news / gmx.net> wrote:
>>> [nil, "aa", "bb"]
>>> ["aa", "bb", "cc"]
>>> ["bb", "cc", "dd"]
>>> ["cc", "dd", "ee"]
>>> ["dd", "ee", "ff"]
>>> ["ee", "ff", "gg"]
>>> ["ff", "gg", "hh"]
>>> ["gg", "hh", "ii"]
>>> ["hh", "ii", "jj"]
>>> ["ii", "jj", "kk"]
>>> ["jj", "kk", nil]
>>
>> Well, it depends.  If, for example, you would want
>> to make a plot that
>> used averaged values (i.e. to smooth the curve) you
>> would not want to see
>> those lines containing nil values IMHO.
>
> It seems like it depends on the application then.

That's what I meant.

>>> Admittedly, it'd be hard to that reasonably with a
>>> variable-size window of even length. But for a
>>> previous-current-next arrangement, it seems to
>> make
>>> more sense to say "there is no previous" with a
>> nil
>>> than to basically skip the first item.
>>
>> It's not that hard to do.
>
> Hmmm, maybe I should say "It's hard to decide what the
> output should look like.
>
> As in, for someone who wants those nils like I do,
> should the first set of arguments from each_window(4)
> be something like
>
> [nil, "aa", "bb", "cc"]
>
> or
>
> [nil, nil, "aa", "bb"]

I'd prefer

[nil, nil, nil, "aa"]

same on the other end: the last window is the one with the last element on 
pos 0 and the rest filled with nils.

> It's obvious with odd length windows, the current item
> should always be the middle one. And with the kind
> that
> doesn't use nils, defining one item as the current one
> probably isn't meaningful anyway, so it's not an
> issue.

I think there's a subtle difference: I think of this as a window slid over 
the sequence and you focus more on the current with previous and next.  IMHO 
both are valid but they obviously differ in what they output.  Plus, with 
your notion (or, what I believe to have recognized as your notion) even 
number of elements does not make sense.  So we probably have

#each_window(size)
#each_context(elements_on_each_side) # the number indicates how many 
elements before and after we see

Is any of this worthwhile to be put into Enumerable?

Kind regards

    robert