On 21/10/05, Kevin Ballard <kballard / gmail.com> wrote:
> Brian Schröäer wrote:
> > Hello Kevin,
> >
> > it is clear that reject without a block does not work, it was more a
> > question of visual parsing. Reject without a block has no meaning,
> > because we need to tell what to reject. And telling this is done with
> > a block. Your quite intelligent magic gives IMHO a wrong meaning to
> > the dot operator. You seem not to call .even? on the result of a
> > reject.
> >
> > Well effectively you do, but I read chained methods as doing a chain
> > of succeding operations on a chain of objects, and that is not what I
> > read when I read (1..100).reject.even? Therefore I proposed
> > (1..100).reject :even?, because there it is made clearer that even is
> > given to reject to do something.
> >
> > Nonetheless go ahed and package it as a gem. I just wanted to voice
> > what was disturbing me with this syntax.
>
> I understand your disturbance, but the syntax you propose makes the
> primary use of this idiom impossible, which is
>
>   [(1..5),(10..15)].each.each { |i| puts i }
>
> What would you suggest, making
>
>   [(1..5),(10..15)].each(:each) { |i| puts i }
>
> behave that way? That looks even more wrong then what my code is doing.
> And what if you have even further nesting?
>
>   [[(1..3), (5..8)], [(4..7), (2..6)]].each.each.each { |i| puts i }
>
> Would that be
>
>   [[(1..3), (5..8)], [(4..7), (2..6)]].each(:each, :each) { |i| puts i
> }
>
> in your syntax? That's even *harder* to read.
>
> Do you see any way to provide the proper behaviour without using the
> syntax my code supports?
>
>
>

Sorry, I do not see a better syntax. But I have to admit that I have
no idea what would be the result of

[[(1..3), (5..8)], [(4..7), (2..6)]].each.each.each { |i| puts i }

(Well if I think long enough, maybe you mean something like

  [[(1..3), (5..8)], [(4..7), (2..6)]].each do | row |
    row.each do | range |
      range.each do |i| puts i end
    end
  end

Which I would prefer about the "new" idiom, but other people may not.

regards,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/