comp.lang.ada
 help / color / mirror / Atom feed
* Re: How to implement a continue statement in Ada?
@ 2000-02-08  0:00 Oliver Kellogg
  2000-02-08  0:00 ` Ted Dennison
  2000-02-08  0:00 ` David Starner
  0 siblings, 2 replies; 12+ messages in thread
From: Oliver Kellogg @ 2000-02-08  0:00 UTC (permalink / raw)


In article <6smb7v$j39$1@nnrp1.dejanews.com>,
  dennison@telepath.com wrote:

> I have used Ada for 9 years now, and have yet to tell myself,
> "gee, I really wish I could do a continue". I think this is
> mostly an issue for C converts.

I care to disagree.

We have a coding rule that forbids the use of goto.
I generally like that rule - it prevents insufficiently
trained people from messing around.

Then again, I have never needed goto for other than
emulating "continue". So I see this as an exceptional case.

I hereby cast my vote for introducing the "continue"
keyword in Ada-0x

Oliver M. Kellogg


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00 How to implement a continue statement in Ada? Oliver Kellogg
  2000-02-08  0:00 ` Ted Dennison
@ 2000-02-08  0:00 ` David Starner
  2000-02-08  0:00   ` Aidan Skinner
  1 sibling, 1 reply; 12+ messages in thread
From: David Starner @ 2000-02-08  0:00 UTC (permalink / raw)


On Tue, 08 Feb 2000 16:36:20 GMT, Oliver Kellogg <okellogg@my-deja.com> wrote:
>In article <6smb7v$j39$1@nnrp1.dejanews.com>,
>  dennison@telepath.com wrote:
>
>> I have used Ada for 9 years now, and have yet to tell myself,
>> "gee, I really wish I could do a continue". I think this is
>> mostly an issue for C converts.
>
>I care to disagree.
>
>We have a coding rule that forbids the use of goto.
>I generally like that rule - it prevents insufficiently
>trained people from messing around.
>
>Then again, I have never needed goto for other than
>emulating "continue". So I see this as an exceptional case.

I disagree with that rule. The goto statement is the most
powerful control structure, and judiciously used, is 
very useful. My most recent use of a goto was to emulate
tail recursion. Does that mean that Ada needs a tail
recursion call? 

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00 How to implement a continue statement in Ada? Oliver Kellogg
@ 2000-02-08  0:00 ` Ted Dennison
  2000-02-09  0:00   ` Roger Barnett
  2000-02-08  0:00 ` David Starner
  1 sibling, 1 reply; 12+ messages in thread
From: Ted Dennison @ 2000-02-08  0:00 UTC (permalink / raw)


In article <87pgm3$o3p$1@nnrp1.deja.com>,
  Oliver Kellogg <okellogg@my-deja.com> wrote:
> In article <6smb7v$j39$1@nnrp1.dejanews.com>,
>   dennison@telepath.com wrote:
>
> > I have used Ada for 9 years now, and have yet to tell myself,
> > "gee, I really wish I could do a continue". I think this is
> > mostly an issue for C converts.
>
> Then again, I have never needed goto for other than
> emulating "continue". So I see this as an exceptional case.
>
> I hereby cast my vote for introducing the "continue"
> keyword in Ada-0x

Hmmm. That quote sounded like me, but I don't exactly share that
sentiment. A quick deja search shows that I posted that back on
September 3, 1998. I realize that at the time no one called me on the
statement, but I think the statue of limitations on arguing the point
with me has long since passed. :-)

For a post of mine on the subject of slightly more recent vintage, try
the following, posted less than a month ago under the thread title of
"Re: bitwise comparators":

> C's continue statement would be helpful often in my Ada code,
> but it does make the code tougher to follow.

As you can see, my opinion has changed slightly over the intervening 1.4
years. Apparently I've written a lot of loops since then. :-)

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00 ` David Starner
@ 2000-02-08  0:00   ` Aidan Skinner
  2000-02-09  0:00     ` Ted Dennison
  2000-02-09  0:00     ` David Starner
  0 siblings, 2 replies; 12+ messages in thread
From: Aidan Skinner @ 2000-02-08  0:00 UTC (permalink / raw)


dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner) writes:

> I disagree with that rule. The goto statement is the most
> powerful control structure, and judiciously used, is 
> very useful. My most recent use of a goto was to emulate
> tail recursion. Does that mean that Ada needs a tail

I would expect this case to be picked up by the compiler, without the
need for an explicit goto. Was there a reason why the appropriate
section of code couldn't be put into a (possibly nested) procedure and 
recurse itself?

- Aidan
-- 
http://www.skinner.demon.co.uk/aidan/
Before asking a tech a question, think: "Does this person care? Is
this in anyway meaningful to their existence?". If the answer is "No", 
please read the documentation supplied, specifically Chapter 9: Suicide.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00 ` Ted Dennison
@ 2000-02-09  0:00   ` Roger Barnett
  0 siblings, 0 replies; 12+ messages in thread
From: Roger Barnett @ 2000-02-09  0:00 UTC (permalink / raw)


In article: <87q53f$6q6$1@nnrp1.deja.com>  Ted Dennison <dennison@telepath.com> 
writes:
> 
> For a post of mine on the subject of slightly more recent vintage, try
> the following, posted less than a month ago under the thread title of
> "Re: bitwise comparators":
> 
> > C's continue statement would be helpful often in my Ada code,
> > but it does make the code tougher to follow.


I've always thought that the C continue statement provides all the
problems of 'goto' but without the clarity  ('break' is almost as bad).

Perhaps if an Ada equivalent required the use of a labelled loop
construct to make it explicit what was being continued ?

-- 
Roger Barnett







^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00   ` Aidan Skinner
@ 2000-02-09  0:00     ` Ted Dennison
  2000-02-12  0:00       ` Jeff Carter
  2000-02-14  0:00       ` Oliver Kellogg
  2000-02-09  0:00     ` David Starner
  1 sibling, 2 replies; 12+ messages in thread
From: Ted Dennison @ 2000-02-09  0:00 UTC (permalink / raw)


In article <m3ya8v1g93.fsf@skinner.demon.co.uk>,
  Aidan Skinner <aidan@skinner.demon.co.uk> wrote:
> I would expect this case to be picked up by the compiler, without the
> need for an explicit goto. Was there a reason why the appropriate
> section of code couldn't be put into a (possibly nested) procedure and
> recurse itself?

That does raise a good issue. Often when this comes up I will fudge it
by putting the code in the loop inside of a subroutine, from which I can
simulate continue with a "return". This could also be done with an
"exit" statement by putting the code in another loop that has an "exit;"
at the end. But that looks silly, while the subroutine often makes some
sense in and of itself.

Given that such workarounds (hacks) exist, why not put continue
capability in Ada 0X by allowing the "exit" statement to exit outside of
a begin..end block? The fact that you can't do this is actually a common
confusion for newbies anyway.

I'll admit its a bit "heavy" of a solution, since it involves another
level of nesting. But it has some advantages to offset that. The
existence of the block would tip readers off that a early termination
may exist. Also, this is more powerful that a meer "continue", because
you can explicitly specify the scope of the statements that get skipped.
For instance, you could have some extra code outside of the block at the
end of the loop that does not get skipped.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-08  0:00   ` Aidan Skinner
  2000-02-09  0:00     ` Ted Dennison
@ 2000-02-09  0:00     ` David Starner
  2000-02-10  0:00       ` Aidan Skinner
  2000-02-12  0:00       ` Character vs. String comparisons (was: Re: How to implement a continue statement in Ada?) Jeff Carter
  1 sibling, 2 replies; 12+ messages in thread
From: David Starner @ 2000-02-09  0:00 UTC (permalink / raw)


On 08 Feb 2000 22:28:08 +0000, Aidan Skinner <aidan@skinner.demon.co.uk> wrote:
>dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner) writes:
>
>> I disagree with that rule. The goto statement is the most
>> powerful control structure, and judiciously used, is 
>> very useful. My most recent use of a goto was to emulate
>> tail recursion. Does that mean that Ada needs a tail
>
>I would expect this case to be picked up by the compiler, without the
>need for an explicit goto. Was there a reason why the appropriate
>section of code couldn't be put into a (possibly nested) procedure and 
>recurse itself?

The code was part of a lexer, and looked like

function lexer return token is begin
<<label>>
-- Bookkeeping
if char(1) = '*' then
-- Deal with it
elsif char(1) = ''' then
...
elsif char (1) = '(' and char (2) = '*' then
   -- Eat the comment
   either goto label or return lexer;
elsif char (1) =  '%' then
...

GNAT didn't recognize it as tail recursion, so the non-recursive
version performed better with certain (pathological) code. I'd
be surprised to find that any Ada compiler did much better on
tail recursion than GNAT, as it's not important for most Ada
programs.

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-09  0:00     ` David Starner
@ 2000-02-10  0:00       ` Aidan Skinner
  2000-02-12  0:00       ` Character vs. String comparisons (was: Re: How to implement a continue statement in Ada?) Jeff Carter
  1 sibling, 0 replies; 12+ messages in thread
From: Aidan Skinner @ 2000-02-10  0:00 UTC (permalink / raw)


dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner) writes:

> On 08 Feb 2000 22:28:08 +0000, Aidan Skinner <aidan@skinner.demon.co.uk> wrote:

> >I would expect this case to be picked up by the compiler, without the
> >need for an explicit goto. Was there a reason why the appropriate

> GNAT didn't recognize it as tail recursion, so the non-recursive
> version performed better with certain (pathological) code. I'd

Having just tried a simple example, it doesn't recognise this at
all. I'm a bit surprised by this TBH...

> tail recursion than GNAT, as it's not important for most Ada
> programs.

I don't know, I use it quite a lot in libra, mostly in the data
structures (a lot of the code which walks through the strucutres uses
tail recursion).

It's probably over-used though, so I may change it...

- Aidan
-- 
http://www.skinner.demon.co.uk/aidan/
Before asking a tech a question, think: "Does this person care? Is
this in anyway meaningful to their existence?". If the answer is "No", 
please read the documentation supplied, specifically Chapter 9: Suicide.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Character vs. String comparisons (was: Re: How to implement a continue  statement in Ada?)
  2000-02-09  0:00     ` David Starner
  2000-02-10  0:00       ` Aidan Skinner
@ 2000-02-12  0:00       ` Jeff Carter
  2000-02-12  0:00         ` David Starner
  1 sibling, 1 reply; 12+ messages in thread
From: Jeff Carter @ 2000-02-12  0:00 UTC (permalink / raw)


David Starner wrote:
> elsif char (1) = '(' and char (2) = '*' then

Is there some reason you didn't write

elsif char (1 .. 2) = "(*";

? Just curious.

-- 
Jeff Carter
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-09  0:00     ` Ted Dennison
@ 2000-02-12  0:00       ` Jeff Carter
  2000-02-14  0:00       ` Oliver Kellogg
  1 sibling, 0 replies; 12+ messages in thread
From: Jeff Carter @ 2000-02-12  0:00 UTC (permalink / raw)


Ted Dennison wrote:
> Given that such workarounds (hacks) exist, why not put continue
> capability in Ada 0X by allowing the "exit" statement to exit outside of
> a begin..end block? The fact that you can't do this is actually a common
> confusion for newbies anyway.

Of course, there is a horrible way to do this already:

loop
   declare
      Continue : exception;
   begin
      ...
      raise Continue; -- Also known as the continue statement
      ...
   exception
   when Continue =>
      null;
   end;
end loop;

-- 
Jeff Carter
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Character vs. String comparisons (was: Re: How to implement a continue  statement in Ada?)
  2000-02-12  0:00       ` Character vs. String comparisons (was: Re: How to implement a continue statement in Ada?) Jeff Carter
@ 2000-02-12  0:00         ` David Starner
  0 siblings, 0 replies; 12+ messages in thread
From: David Starner @ 2000-02-12  0:00 UTC (permalink / raw)


On Sat, 12 Feb 2000 21:50:33 GMT, Jeff Carter <jrcarter010@earthlink.net> wrote:
>David Starner wrote:
>> elsif char (1) = '(' and char (2) = '*' then
>
>Is there some reason you didn't write
>
>elsif char (1 .. 2) = "(*";

Yes. It actually looked like 
   elsif char (I + 1) = '(' and then char (I + 2) = '*' then ...
The way the buffer was set up, the trailing character would always be
a space. As long as anything didn't read past a space, I don't have
to take the extra code to check that I < EOL. char (I+1 .. I + 3) = 'for'
could potentially overflow the buffer, whereas char(I+1) = 'f' and then
char (I+2) = 'o' and then char (I + 3) = 'r' won't. Also, it looked like
elsif char (I+1) = '(' then
   if char (I+2) = '*' then
      -- Do comment things
   else
      -- Do open parenthesis things
   end if;
...
-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to implement a continue statement in Ada?
  2000-02-09  0:00     ` Ted Dennison
  2000-02-12  0:00       ` Jeff Carter
@ 2000-02-14  0:00       ` Oliver Kellogg
  1 sibling, 0 replies; 12+ messages in thread
From: Oliver Kellogg @ 2000-02-14  0:00 UTC (permalink / raw)


In article <87s92d$lj1$1@nnrp1.deja.com>,
  Ted Dennison <dennison@telepath.com> wrote:

> Given that such workarounds (hacks) exist, why not put continue
> capability in Ada 0X by allowing the "exit" statement to exit
> outside of a begin..end block? The fact that you can't do this
> is actually a common confusion for newbies anyway.

A agree wholeheartedly. This should apply to both the
exit and the continue statement.

However, I still think adding a "continue" statement
to Ada is a good idea.

"continue" is complementary to "exit" in nature
and the same syntax rules should apply to both.
E.g. the continue statement could take an optional
loop_designator (just like exit) to make possible
continuing to outer loops in the case of nested loops.

Oliver M. Kellogg
-- okellogg at freenet dot de



Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2000-02-14  0:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-08  0:00 How to implement a continue statement in Ada? Oliver Kellogg
2000-02-08  0:00 ` Ted Dennison
2000-02-09  0:00   ` Roger Barnett
2000-02-08  0:00 ` David Starner
2000-02-08  0:00   ` Aidan Skinner
2000-02-09  0:00     ` Ted Dennison
2000-02-12  0:00       ` Jeff Carter
2000-02-14  0:00       ` Oliver Kellogg
2000-02-09  0:00     ` David Starner
2000-02-10  0:00       ` Aidan Skinner
2000-02-12  0:00       ` Character vs. String comparisons (was: Re: How to implement a continue statement in Ada?) Jeff Carter
2000-02-12  0:00         ` David Starner

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