[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6585] Re: best way to interleaf arrays?

From: Dave Thomas <Dave@...>
Date: 2000-11-27 00:51:21 UTC
List: ruby-talk #6585
David Alan Black <dblack@candle.superlink.net> writes:

> Is there a nice Ruby idiom for interleafing arrays?  It's not hard to
> write a method that will do it, but I'd be interested in knowing how
> it's been done in the past.

Matz has a technique for simulating external iterators using threads,
which would do it.

You could also do it the boring way:

     def interleave(a1, a2)
       n = a1.size
       n = a2.size if a2.size < n
       (0...n).collect {|i| [a1[i], a2[i]]}.flatten + a1[n..-1] + a2[n..-1]
     end

On the Hash front, I'm starting to think it would be useful to have

   Hash.from_array(ary, value)

which was equivalent to

   def Hash.from_array(ary, value = 1)
      h = {}
      if block_given?
        ary.each {|k| h[k] = yield(k,value) }
      else
        ary.each {|k| h[k] = value }
      end
      h
   end


Regards


Dave



In This Thread