[#4567] Re: What's the biggest Ruby development? — Aleksi Niemel<aleksi.niemela@...>

Dave said:

18 messages 2000/08/23
[#4568] Q's on Marshal — Robert Feldt <feldt@...> 2000/08/23

[#4580] RubyUnit testcase run for different init params? — Robert Feldt <feldt@...> 2000/08/25

[#4584] Re: RubyUnit testcase run for different init params? — Dave Thomas <Dave@...> 2000/08/25

Robert Feldt <feldt@ce.chalmers.se> writes:

[#4623] Re: RubyUnit testcase run for different init params? — Robert Feldt <feldt@...> 2000/08/28

On Sat, 26 Aug 2000, Dave Thomas wrote:

[#4652] Andy and Dave's European Tour 2000 — Dave Thomas <Dave@...>

24 messages 2000/08/30
[#4653] Re: Andy and Dave's European Tour 2000 — matz@... (Yukihiro Matsumoto) 2000/08/30

Hi,

[#4657] Ruby tutorials for newbie — Kevin Liang <kevin@...> 2000/08/30

Hi,

[ruby-talk:4563] Continuations revisited

From: "Sergey Abel" <abel_sm@...>
Date: 2000-08-23 12:22:49 UTC
List: ruby-talk #4563
Hi,

Pondering on the producer/consumer model showed by Jim Weirich
in [ruby-talk:04482], I came to 2 points:

1. Repetitive executing of callcc statement should be avoided.
In particular, producer should not use `each' method to deliver
its data.

2. In general case, consumer should have possibility to stop
further processing.

Here's my example, with dramatically increased performance:

# ======================================
# Usage: producer 100, consumer 50

def producer ( limit, consumer )
  i = 0
  return if callcc { |@producer| }
  i += 1
  consumer.call i unless i > limit
end

def consumer ( limit )
  i = callcc { |cc| return cc }
  print "#{i} "
  @producer.call i < limit ? nil : 0
end
# ======================================

But still, I cannot imagine the case when continuations are
_really_ needed.

Sergey

God bless our submariners





In This Thread

Prev Next