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


Groups > comp.lang.forth > #24849

Re: How to abort loops and other return stack fiddling words?

From rickman <gnuarm@gmail.com>
Newsgroups comp.lang.forth
Subject Re: How to abort loops and other return stack fiddling words?
Date 2013-07-29 11:01 -0400
Organization A noiseless patient Spider
Message-ID <kt5vst$p23$1@dont-email.me> (permalink)
References (4 earlier) <2013Jul22.180100@mips.complang.tuwien.ac.at> <ksjmeb$1vj$1@dont-email.me> <BKGdnWp-A4QhG3LMnZ2dnUVZ_hednZ2d@supernews.com> <kt1uj5$id$1@dont-email.me> <FbKdnRHQ9JOxRWnMnZ2dnUVZ_oednZ2d@supernews.com>

Show all headers | View raw


On 7/28/2013 4:37 AM, Andrew Haley wrote:
> rickman<gnuarm@gmail.com>  wrote:
>> On 7/24/2013 3:48 AM, Andrew Haley wrote:
>>> rickman<gnuarm@gmail.com>   wrote:
>>>> On 7/22/2013 12:01 PM, Anton Ertl wrote:
>>>>> Mark Wills<markrobertwills@yahoo.co.uk>    writes:
>>>>>> All of which voids the entire point - that an AGAIN loop is
>>>>>> *supposed* to be infinate. So if you *do* need to exit the loop,
>>>>>> you shouldn't be using it.
>>>>>
>>>>> Maybe that's your house style, but not everybody has to follow your
>>>>> house style.  In standard Forth AGAIN is just an unconditional branch
>>>>> backwards.  You can use it for building infinite loops, but also for
>>>>> other purposes.
>>>>
>>>> Do you have examples of loops with exits that are better served by AGAIN
>>>> than they are with UNITL or WHILE?  Are you talking about error
>>>> handling?   I can't think of any example where I thought it better to
>>>> make an infinite loop with an error exit than just using a loop with an
>>>> exit condition like UNTIL or WHILE.
>>>
>>> The classic case is
>>>
>>> begin
>>>     something
>>>     something_else if  maybe if  yes_action  exit  then  step  then
>>>     more
>>> again
>>>
>>> It's possible to restructure this, but not easy.
>>
>> Wow! I can't even understand what this is saying.  What are "maybe" and
>> "step"?  I guess I don't get any sense of why this code is written this
>> way.
>
> It might be stepping through some kind of data structure, with actions
> to be performed iff [1] a node exists and it has a particular value.

Which word does which in the sequence above?  I need this to be a bit 
more concrete.  Your loop runs without executing the 'step' word if 
something_else does not return a TRUE.  So sometimes the loop is 
stepping, other times it isn't... I find that very confusing without 
some idea of context.  Still, it's not really a problem.


>> begin
>>     something
>>     something_else maybe OVER AND 0= while if  step  then
>>     more
>> repeat
>> yes_action  ;
>>
>> Is that so complex?  Did I miss something?
>
> Yes, you did.  Perhaps it's not safe to execute MAYBE unless
> SOMETHING_ELSE is true.  And it's also a waste of CPU time: as soon as
> you've determined that SOMETHING_ELSE is false, there's no point
> executing MAYBE .  You can do it with multiple WHILEs, but it's no
> easier to understand the code.

Ok, but that the intention is hard to tell from the code segment.  I 
think this would be better solved by factoring.

: loop_control
   something_else if maybe if FALSE else TRUE step then then
;

begin
     something
     loop_control while
     more
repeat
yes_action  ;

I don't think this is overly complex and does what you needed, no?

I think my real issue with your example is just the use of EXIT. 
Regardless of how some people practice coding, I learned structured 
programming in college and it made a significant impact on me.  When I 
look at your code example, all sorts of flags pop up in my mind having 
to do with exiting a subroutine from other than the end.  It *does* make 
it harder to read the code (assuming there is any significant code to 
read) and leads to errors which can be harder to debug.

I will grant you that in Forth the short code segments often used make 
the use of EXIT easier and less trouble prone, but as you can see above 
the factoring actually has improved the code so that the main word deals 
with what is being done by the loop while the factored word deals with 
how the loop is controlled.  Also, the yes_action word is outside of the 
loop where (in my mind) it logically belongs (again the structured 
programming influence) not to mention the fact that the factored version 
is just plain easier to read.


>> Have you ever needed to use something like this?
>
> Heavens, yes!  Hundreds of times.  There's nothing special about it.
> It's not obscure.

You are entitled to your coding style.  But I think your premise that 
"It's possible to restructure this, but not easy." is busted.  The only 
hard part was understanding what the example was supposed to do.

-- 

Rick

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


Thread

How to abort loops and other return stack fiddling words… Christian Kellermann <ckeen@pestilenz.org> - 2013-07-22 11:54 +0200
  Re: How to abort loops and other return stack fiddling words… Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-22 04:18 -0700
    Re: How to abort loops and other return stack fiddling words… Christian Kellermann <ckeen@pestilenz.org> - 2013-07-22 14:31 +0200
      Re: How to abort loops and other return stack fiddling words… daveyrotten <danw8804@gmail.com> - 2013-07-22 08:31 -0700
    Re: How to abort loops and other return stack fiddling words… Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-07-22 13:56 +0100
      Re: How to abort loops and other return stack fiddling words… Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-22 06:46 -0700
        Re: Re: How to abort loops and other return stack fiddling words… anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-22 16:01 +0000
          Re: How to abort loops and other return stack fiddling words… rickman <gnuarm@gmail.com> - 2013-07-22 12:31 -0400
            Re: Re: How to abort loops and other return stack fiddling words… anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-22 16:36 +0000
            Re: How to abort loops and other return stack fiddling words… "Ed" <invalid@invalid.com> - 2013-07-24 12:18 +1000
            Re: How to abort loops and other return stack fiddling words? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-24 02:48 -0500
              Re: How to abort loops and other return stack fiddling words? rickman <gnuarm@gmail.com> - 2013-07-27 22:15 -0400
                Re: How to abort loops and other return stack fiddling words? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-28 03:37 -0500
                Re: How to abort loops and other return stack fiddling words? rickman <gnuarm@gmail.com> - 2013-07-29 11:01 -0400
                Re: How to abort loops and other return stack fiddling words? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-29 11:07 -0500
                Re: How to abort loops and other return stack fiddling words? rickman <gnuarm@gmail.com> - 2013-07-29 12:32 -0400
                Re: How to abort loops and other return stack fiddling words? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-29 11:54 -0500
                Re: How to abort loops and other return stack fiddling words? rickman <gnuarm@gmail.com> - 2013-07-29 13:19 -0400
                Re: How to abort loops and other return stack fiddling words? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-29 15:27 -0500
                Re: How to abort loops and other return stack fiddling words? Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-28 03:20 -0700
                Re: How to abort loops and other return stack fiddling words? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-28 08:17 -0500
        Re: How to abort loops and other return stack fiddling words… Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-07-22 18:07 +0100
      Re: Re: How to abort loops and other return stack fiddling words… albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-22 14:12 +0000
        Re: How to abort loops and other return stack fiddling words… Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-07-22 17:49 +0100
      Re: How to abort loops and other return stack fiddling words… hughaguilar96@yahoo.com - 2013-07-22 20:25 -0700
  Re: How to abort loops and other return stack fiddling words? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-22 07:54 -0500

csiph-web