Re: Goto (Was Re: Open Source)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Juergen Luethje wrote:
> 
> Me wrote:
> 
> > Pete Lomax wrote:
> > 
> > > Juergen Luethje wrote:
> > > > 
> > > > This whole discussion is not logical for me. Someone asks for intrducing
> > > > GOTO into Euphoria, and other people make suggestions how to limit the
> > > > damage then.
> > > > The first question should be: Why does someone want GOTO, and exactly
> > > > _for what purposes_? I'm pretty sure then we can find more appropriate
> > > > constructs for the desired purposes -- high level constructs for the
> > > > high level language Euphoria.
> > > > 
> > > Since you ask, I would say to translate a working program written in
> > > another
> > > language to Eu.
> > 
> > This is a concrete reason which provides a solid basis for discussing,
> > thanks.
> > 
> > > As I recently said, I am not advocating goto, just not standing
> > > against it. Here is one case you probably already saw:
> > > 
> > > int parse()
> > > {
> > >     Token   tok;
> > > 
> > > reading:
> > >     tok = gettoken();
> > >     if (tok == END)
> > >         return ACCEPT;
> > > shifting:
> > >     if (shift(tok))
> > >         goto reading;
> > > reducing:
> > >     if (reduce(tok))
> > >         goto shifting;
> > >     return ERROR;
> > > }
> > 
> > If I didn't make a mistake, this translates to the following Eu program:
> > }}}
<eucode>
> > procedure foo ()
> >    Token tok
> >    
> >    while 1 do
> >       -- reading
> >       tok = gettoken()
> >       if tok = END then
> >          return ACCEPT
> >       end if
> >       
> >       while 1 do
> >          -- shifting
> >          if shift(tok) then
> >             exit
> >          end if
> >          -- reducing
> >          if not reduce(tok) then
> >             return ERROR
> >          end if
> >       end while
> >    end while
> > end procedure
> > </eucode>
{{{

> 
> Must of course be 'function', not 'procedure'.
> 
> I actually would prefer to write the code this way:
> }}}
<eucode>
> function foo ()
>    Token tok
>    
>    tok = gettoken()
>    while tok != END do
>       while not shift(tok) do
>          if not reduce(tok) then
>             return ERROR
>          end if
>       end while
>       tok = gettoken()
>    end while
>    return ACCEPT
> end function
> </eucode>
{{{

> 
> Now this is short and pretty clear. Without using GOTO, the structure of
> the program (2 nested loops) is directly visible. So the "nature" of the
> program can be understood immediately and intuitively.


Not me. 
So i can assume you'll go with this construct and we'll never get a goto.

Kat
 
> Regards,
>    Juergen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu