Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #26343

Re: Co-routines a la Knuth

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Co-routines a la Knuth
Date 2013-10-07 12:33 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2013Oct7.143349@mips.complang.tuwien.ac.at> (permalink)
References <6b24531a-7c25-4a3e-9b60-21af2bb89dae@googlegroups.com>

Show all headers | View raw


mhx@iae.nl writes:
>Donald E. Knuth's Chapter 1.4.2 in 'Fundamental Algorithms' 2nd Ed., 
>has interesting, but unconvincing, things to say about coroutines. 
>
>I found a co-routine implementation that doesn't use the R-stack 
>at all and only needs a single variable. (It is a special case.)

That may be enough for Knuth's example, but general coroutines should
have their own stacks.  As Knuth himself writes:

|The usefulness of the couroutine idea emerges when both A and B are
|complicated and each one calls the other one in numerous places.

E.g., you have data in a sort tree, and you want to output it in
filled lines (but without wrapping lines); A would walk the tree using
recursion, and B would be a doubly nested loop.  E.g., what if, in
your later example with a DO LOOP in the generator, you would also
like to have a DO LOOP in the printer?

IMO coroutines are a natural extension of the classical Forth
cooperative multi-tasking model.  Each coroutine has its own task, and
calling the other performs a task switch directly to the task of the
other coroutine (without the round-robin scheduler) and typically
moves some data or floating-point stack items from one task to the
other.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2013: http://www.euroforth.org/ef13/

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Co-routines a la Knuth mhx@iae.nl - 2013-10-05 11:50 -0700
  Re: Co-routines a la Knuth Paul Rubin <no.email@nospam.invalid> - 2013-10-05 14:15 -0700
    Re: Co-routines a la Knuth mhx@iae.nl - 2013-10-06 03:22 -0700
      Re: Co-routines a la Knuth mhx@iae.nl - 2013-10-06 09:58 -0700
  Re: Co-routines a la Knuth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-10-07 12:33 +0000
    Re: Co-routines a la Knuth m.a.m.hendrix@tue.nl - 2013-10-07 07:17 -0700
      Re: Co-routines a la Knuth mhx@iae.nl - 2013-10-07 13:43 -0700
        Re: Co-routines a la Knuth "Elizabeth D. Rather" <erather@forth.com> - 2013-10-07 12:58 -1000
          Re: Co-routines a la Knuth mhx@iae.nl - 2013-10-08 23:58 -0700
            Re: Co-routines a la Knuth "Elizabeth D. Rather" <erather@forth.com> - 2013-10-08 21:08 -1000
      Re: Co-routines a la Knuth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-10-08 15:05 +0000
        Re: Co-routines a la Knuth mhx@iae.nl - 2013-10-09 13:23 -0700

csiph-web