Hi --

On Fri, 15 Nov 2002, Tim Sutherland wrote:

> In article <Pine.LNX.4.44.0211142157370.25867-100000 / candle.superlink.net>,
> dblack / candle.superlink.net wrote:
> >Hi --
> >
> >On Fri, 15 Nov 2002, Tim Sutherland wrote:
> [...]
> >> [a, b, c].zip { |x, y, z| x*y + z } #=> [5, 2, 7]
> >>
> >> Now zip is like lisp's map.
> >
> >The optional block is cool, but I don't know about having the return
> >value of the method being different depending on the presence or
> >absence of a block.  I'm not sure, though.
>
> Thanks for the reply David. By return value, do you mean nil vs exception
> for block vs non-block?

No, I mean the actual return value of the method call, which is a
separate matter from the block.  In your example, if there were no
block, the return value would be different.  In other words, given:

  n = [a,b,c].zip
  m = [a,b,c].zip { |x,y,z| x*y+z }

n and m would not be the same.  That's where I'm scratching my head
and wondering if that's the best way.

With methods whose blocks are not optional, you can just decide and
then the behavior will be consistent; for example, #map returns an
array consisting of the aggregate of what happened in the block, while
#each returns the receiver.  My instinct is to think that methods with
optional blocks should also have consistent return values, but I'm not
entirely sure.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav