Hi,

In message "[ruby-talk:00667] How do I use `callcc'"
    on 99/08/15, Clemens Hintze <c.hintze / gmx.net> writes:

|In Modula 2 I have mainly three procedures, that deal with Coroutines:
|NEWPROCESS, TRANSFER and IOTRANSFER.

|Can I do similiar thing with Ruby's continuations? Can I perhaps
|emulate the three procedures NEWPROCESS, TRANSFER and IOTRANSFER?

Continuations are say dynamic labels;  you can't alter them.  But
using it, you can emulate coroutines.  Here's something similar.

  MaxHiHo = 17;
  def WriteHi
    callcc{|c| return c}
    loop do
      callcc{|c|$Hi=c}
      print "Hi" 	  	 	      	 	
      $Ho.call
    end
  end

  def WriteHo
    i = 0;
    callcc{|c| return c}
    loop do
      callcc{|c|$Ho=c}
      print "Ho"
      i += 1
      if i > MaxHiHo then
        print "\n"
        i= 0;
      end;
      $Hi.call
    end;
  end

  $Ho = WriteHo()
  $Hi = WriteHi()
  $Ho.call

By the way, why don't you use thread, instead of emulating coroutine
by yourself.

|I have thougth, the execution would go back till after (1), so that the
|calculation will be performed, and then the result would be returned.
|But it seems also to influence the global execution. Because it goes
|not only back to (1) but back to (2).

As I said before continuations are labels.  calling Continuation#call
jumps into the place where the continuation created.

                                                        matz.