Ruby-dev summary 18613-18710

Hi all,

One of the happiest things for me in RubyConf2002 was
to meet readers of this summary. Thanks again!

And, this is a summary of ruby-dev ML in these days.

---- ruby-dev #18613-18710 (2002-10-31 … 2002-11-08) ----

[ruby-dev:18651] Enumerable#zip

Matz implemented Enumerable#zip method, but he has not
decide its behavior yet.

Enumerable#zip is a method to mix some sequences(Array or
Object which has to_ary method). But, when length of
sequences are not same, the behavior is not clear.

a = [1,2,3,4]
b = [2,4]
a.zip(b) #=> ?

a.) a.zip(b) #=> [[1,2],[2,4],[3,nil],[4,nil]]

b.) a.zip(b) #=> [[1,2],[2,4]]

c.) a.zip(b) #=> [[1,2],[2,4],[3,nil],[4,nil]]
b.zip(a) #=> [[2,1],[4,2]]

e.) a.zip(b) #=> raise Exception (ArgumentError(?))

There is a discussion whether Enumerable#zip is appropriate or not.

ex.
* Enumerable.zip(a, b, c…)
* Array.zip(a, b, c…)
* [a, b, c…].zip

[ruby-dev:18652] Re: 1.6.8 preview

The first preview version of Ruby 1.6.8 is available.

ftp.ruby-lang.org:/pub/ruby/1.6/ruby-1.6.8-preview1.tar.gz

(2002/11/11: now second preview version of one is avalible.
ftp.ruby-lang.org:/pub/ruby/1.6/ruby-1.6.8-preview2.tar.gz )

This package is just only preview and it has a well known
problem (dRuby’s UnitTest is not passed). A patch to solve
this problem has been made by nobu, but Matz does not have
enough time to verify it.
Moreover, Akinori MUSHA got a report that 1.6.8 preview1 made
too many warning with -w option ([ruby-dev:18705]).

[ruby-dev:18683] Re: ERb

Masatoshi SEKI released ERb 2.0b2.

http://www2a.biglobe.ne.jp/~seki/ruby/erb-2.0b2.tar.gz  

ERb is pure Ruby implementation of eRuby. If there is no
problem, it will be in standard distribution of Ruby.

Regards,

TAKAHASHI ‘Maki’ Masayoshi E-mail: maki@rubycolor.org

In article 20021112020739J.maki@rubycolor.org,

Hi all,

One of the happiest things for me in RubyConf2002 was
to meet readers of this summary. Thanks again!

It was good to meet you too.

And, this is a summary of ruby-dev ML in these days.

---- ruby-dev #18613-18710 (2002-10-31 … 2002-11-08) ----

[ruby-dev:18651] Enumerable#zip

Matz implemented Enumerable#zip method, but he has not
decide its behavior yet.

Enumerable#zip is a method to mix some sequences(Array or
Object which has to_ary method). But, when length of
sequences are not same, the behavior is not clear.

a = [1,2,3,4]
b = [2,4]
a.zip(b) #=> ?

a.) a.zip(b) #=> [[1,2],[2,4],[3,nil],[4,nil]]

b.) a.zip(b) #=> [[1,2],[2,4]]

c.) a.zip(b) #=> [[1,2],[2,4],[3,nil],[4,nil]]
b.zip(a) #=> [[2,1],[4,2]]

e.) a.zip(b) #=> raise Exception (ArgumentError(?))

There is a discussion whether Enumerable#zip is appropriate or not.

ex.

  • Enumerable.zip(a, b, c…)
  • Array.zip(a, b, c…)
  • [a, b, c…].zip

I guess I’m having a hard time seeing the usefulness of this (not saying
it wouldn’t be useful to someone). Also, the name ‘zip’ is usually
associated with compression so it could be doubly confusing.
Looks like option ‘c’ might be best.

BTW: While were on the subject of adding operators to the Array class… I
would find an operator to do the Cartesian product of
the two arrays to be useful:
a = [1,2,3,4]
b = [2,4]

a.x(b) #=> [[1,2],[1,4],[2,2],[2,4],[3,2],[3,4],[4,2],[4,4]]
perhaps it could be:
a*b ,but '*' is already defined on the Array class, however if the 

argument is an array instead of an integer then the Cartesian product
could be done between the two arrays.

Phil

···

TAKAHASHI Masayoshi maki@rubycolor.org wrote:

Maybe you could use something similar to the default value / block in
Hash.new, something like

a = [1,2,3,4]
b = [2,4]

a.zip(b) #=> [[1,2],[2,4]]
a.zip(b, nil) #=> [[1,2],[2,4],[3,nil],[4,nil]]
a.zip(b, “missing”) #=> [[1,2],[2,4],[3,“missing”],[4,“missing”]]

d = 0
a.zip(b) { d += 1 } #=> [[1,2],[2,4],[3,1],[4,2]]

BTW, how is it implemented? Using threads / continuations / something
else?

Regards,
Pit

···

On 12 Nov 2002 at 2:19, TAKAHASHI Masayoshi wrote:

(…)
[ruby-dev:18651] Enumerable#zip

Matz implemented Enumerable#zip method, but he has not
decide its behavior yet.

Enumerable#zip is a method to mix some sequences(Array or
Object which has to_ary method). But, when length of
sequences are not same, the behavior is not clear.

a = [1,2,3,4]
b = [2,4]
a.zip(b) #=> ?

a.) a.zip(b) #=> [[1,2],[2,4],[3,nil],[4,nil]]

b.) a.zip(b) #=> [[1,2],[2,4]]

c.) a.zip(b) #=> [[1,2],[2,4],[3,nil],[4,nil]]
b.zip(a) #=> [[2,1],[4,2]]

e.) a.zip(b) #=> raise Exception (ArgumentError(?))
(…)

Hi –

Hi all,

One of the happiest things for me in RubyConf2002 was
to meet readers of this summary. Thanks again!

It was good to see you again – looking forward to next year!

[ruby-dev:18651] Enumerable#zip

Matz implemented Enumerable#zip method, but he has not
decide its behavior yet.

Enumerable#zip is a method to mix some sequences(Array or
Object which has to_ary method). But, when length of
sequences are not same, the behavior is not clear.

[…]

a = [1,2,3,4]
b = [2,4]
a.zip(b) #=> ?

c.) a.zip(b) #=> [[1,2],[2,4],[3,nil],[4,nil]]
b.zip(a) #=> [[2,1],[4,2]]

That makes sense to me. The iteration is over the receiver, so the
length of the result is the same as the length of the receiver.
Something like:

module Enumerable
def zip(other)
(0…size).map {|i| [to_a[i],other.to_a[i]] }
end
end

(Of course it would look better if we had #map_with_indices :slight_smile:

I once wrote something called Array#braid, which zipped two or more
arrays:

[1,2,3].braid([4,5,6],[7,8,9])

 # => [ [1,4,7], [2,5,8], [3,6,9] ]

Was there any discussion of a generalized version of zip?

David

···

On Tue, 12 Nov 2002, TAKAHASHI Masayoshi wrote:


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

Hi,

···

In message “Re: ruby-dev summary 18613-18710” on 02/11/15, Tim Sutherland timsuth@ihug.co.nz writes:

How about the latter, with an optional block.

a = [1, 0, 3]
b = [2, 1, 2]
c = [3, 2, 1]

[a, b, c].zip { |x, y, z| x*y + z } #=> [5, 2, 7]

Now zip is like lisp’s map.

Interesting feature, but it should not be named “zip”.

						matz.

Hi all,

With a little help from the fine folks on IRC, here’s a bit of addenda
to my Ruby Conf talk - quick enumerators using hashslice and ranges:

require "hashslice"
h = {}
h[(1…26)] = [(“a”…“z”)]

h[1] -> "a"
h[26] -> “z”, etc

Perhaps a bit Perl-like in obfuscation, but might be handy.

Michael Granger also pointed out that it’s useful for value
transposition (if that’s the correct term):

h = {:name1 => “Matz”, :name2 => “Nobu”}
h[:name1,:name2] = h[:name2,:name1]

Enjoy!

Regards,

Dan

Maybe you could use something similar to the default value / block in
Hash.new, something like

a = [1,2,3,4]
b = [2,4]

a.zip(b) #=> [[1,2],[2,4]]
a.zip(b, nil) #=> [[1,2],[2,4],[3,nil],[4,nil]]
a.zip(b, “missing”) #=> [[1,2],[2,4],[3,“missing”],[4,“missing”]]

Sounds good to me

d = 0
a.zip(b) { d += 1 } #=> [[1,2],[2,4],[3,1],[4,2]]

This one’s too confusing, IMO. I’d rather give it a new name, like
zipfill.

Another potentially useful variant:

a.zip {block}

as a shorthand for (not proper ruby, but gets the point across)

a.collect {|i| [i,yield i]} {block}

(and maybe a.izip, where zip:izip::each:each_index)

martin

···

Pit Capitain pit@capitain.de wrote:

It’s called “zipWith3” in Haskell. In Ruby no such limitation is
required and we could get along with a single zip method for Haskells
zip, zip3, zipWith and ZipWith3 zoo. I have posted a ruby implementation
in another mail to this list.

···

On 2002-11-15 14:04:52 +0900, Yukihiro Matsumoto wrote:

[a, b, c].zip { |x, y, z| x*y + z } #=> [5, 2, 7]

Now zip is like lisp’s map.
Interesting feature, but it should not be named “zip”.


Four legs good, two legs bad.
– George Orwell, “Animal Farm”