comp.lang.ada
 help / color / mirror / Atom feed
From: mernst@desy.de (Matthias Ernst)
Subject: Re: Eiffel gripe (was Ada vs. Eiffel)
Date: 12 Sep 1994 09:35:14 GMT
Date: 1994-09-12T09:35:14+00:00	[thread overview]
Message-ID: <3517ci$f12@dscomsa.desy.de> (raw)
In-Reply-To: 34e4rgINNqdg@ephor.tusc.com.au

Anthony Shipman (als@tusc.com.au) wrote:
: In <1994Sep4.100449.205@aldur.demon.co.uk> neil@aldur.demon.co.uk (Neil Wilson) writes:

: The absence of a 'break'-like statement or early return can make coding a
: lot more tedious than it should be.  Since code with a break or early return
: can be mechanically translated into code without why have the programmer do
: it?

: The one type of loop that has been settled on doesn't cover the range of
: loop architectures in common use.  It provides a

:     loop
: 	if not condition then break;
: 	B;
:     end

: style of loop whereas a 

:     loop
: 	A;
: 	if not condition then break;
: 	B;
:     end

: style would be more general.  The second reduces to the first by
: omitting A but the first cannot be used to implement the second without
: duplicating code as in:

: [deleted]

Ever looked at Sather ?
Its iteration approach is IMO the synthesis of powerful but simple constructs.

A loop in Sather consists of a
- loop ... end frame.
- normal code
- iter calls

An iter is something like a function/procedure with the difference
that it has control of the embedding loop: it may either 'yield'
control to the loop or 'quit' which exits the loop.
Sequential calls to the iter resume execution after the last 'yield' statement.

Examples are better than thousand words:

[conservative]:

i := 1;
sum := 0;
loop
    sum := sum + i;
until i = 10;


[innovative]:

sum := 0;
loop
    sum := sum + 1.upto!(10);
end;

or

i := 0;
loop while i<10
   CODE;
   i := i+1;
end;

better:
loop 10.times!;
    CODE
end;


Here the iters upto! and times! encapsulate
- initialization
- loop variance
- termination

Note that the standard loop controls while, until, break can easily be
expressed as iters:
    while yields as long as its argument is true
    until yields as long as its argument is false
    break quits immediately

One difference: calls to while! and until! can appear ANYWHERE in the loop:
loop
    i := get_int;
    while!(i ~= 0);

    print 1/i;
end;

Further you can easily generalize iteration through containers of any kind.
If you're interested, look at the Sather home page:
http://www.icsi.berkeley.edu/Sather
There is a tech report about iters.

Matthias 





: -- 
: Anthony Shipman                 "You've got to be taught before it's too late,
: TUSC Computer Systems Pty Ltd    Before you are six or seven or eight,
:                                  To hate all the people your relatives hate,
: E-mail:  als@tusc.com.au         You've got to be carefully taught."  R&H



  parent reply	other threads:[~1994-09-12  9:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <DERWAY.94Aug23180251@alumni.ndc.com>
     [not found] ` <DERWAY.94Aug31133058@alumni.ndc.com>
     [not found]   ` <1994Sep1.094653@lglsun.epfl.ch>
     [not found]     ` <34473c$ru5@info2.rus.uni-stuttgart.de>
     [not found]       ` <344isl$brd@Starbase.NeoSoft.COM>
     [not found]         ` <3450li$t04@disuns2.epfl.ch>
1994-09-06 13:41           ` Ada vs. Eiffel Graham Perkins
     [not found]           ` <1994Sep4.100449.205@aldur.demon.co.uk>
     [not found]             ` <34e4rgINNqdg@ephor.tusc.com.au>
1994-09-12  9:35               ` Matthias Ernst [this message]
1994-09-12 13:52                 ` Eiffel gripe (was Ada vs. Eiffel) Robert Dewar
1994-09-14  2:07                   ` Matt Kennel
1994-09-14 15:37                     ` Jacob Gore
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox