RE: Kat's goto

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

On 6 Feb 2002, at 4:00, euman at bellsouth.net wrote:

> 
> 
> David Cuny wrote:
> > Kat wrote:
> > 
> > > I cannot afford to buy the code at this time, or i'd be 
> > > adding a goto.
> > 
> > Hopefully Robert's documentation will help with this. After all, it is 
> > an 
> > initial release.
> > 
> > I concur with Bernie - I don't know any simple way to add a GOTO. But if I
> > figure it out, you'll be the first one to get a copy of it!
> > 
> > -- David Cuny


Bless you, David, in your favorite religion of your choosing!

> Hi,
> 
> Either Im totaly missing something about GOTO or I just
> havent had a real pressing need for them in any language
> I've tried out.
> 
> I started out with Hyperkinetix, Builder in 1993 (I think 93)
> anyway, I found a few programs I wrote in builder back then
> and I did use "goto" but very little.
> 
> Why should we even go there (I mean GO TO there)
> when we can simply use call_backs or routine_id
> to do the very samething a GOTO would do.

Routine_id isn't a reference point in nested If clauses. When i am writing a 
bit of http parsing, and the code refires with windose, for the same http file 
being recieved, a few gotos can save the day by simply saying "ok, we are at 
this point in processing the file at this event firing, do this and goto the end
of
the event. The only way i can see doing this without gotos is a slew of 
functions to call for each test, flow control vars, and repeatedly testing those
flow control vars.
 
> I could possibly see a need if you perhaps wanted to setup a line number 
> type scripting language but, there isnt a need for them in Euphoria. It 
> really would confuse people I think if Eu had them.
> 
> euman at bellsouth.net

No need for line numbers. Mirc has no line numbers. And no need for 
indenting either tho, which some other languages mandate.

(Mirc and Eu do not have a CASE statement)

food {
if $istok(%food,%foodlist,$asc(;)) { goto %food }

; code to query user about their alledged "food"
goto eofood -- because it's not food

:cookie | sendcookies | goto eofood
:cookies | send cookies | goto eofood
:crackers | specifytype | goto eofood
:pizza | offer types | goto eofood
; etc

:eofood
}

(mirc and Eu do not have a REPEAT statement)

repeat_test {
:begin
 ; code to do things
 if ( conditions ok ) { goto begin }
}

(Eu doesn't have a GET_OUT_OF_5_LEVELS_OF_LOOPS_NOW or a 
BACK_UP_4_LOOP_LEVELS_AND_RESTART_THOSE_LOOPS )

nested_example {
 if _____
  :top_loop
   if _____
    if ______
     if ______
      if ( something) { goto top_loop }
        if whatever { goto eonested_example }
      }
     }
    }
   }
  }
:eonested_example
}

One goto can get you out of the deepest nested code loops to one unique 
point, to continue processing at the place you need it to be. As you know, 
the C64 BASIC was line numbered, and the native GOTO went to line 
numbers. When i added :targets, i didn't limit where they could go, and i 
enjoyed the freedom of an interpreted language to edit in code to goto a 
variable target, a fixed memory location, a program location with a ":target" in
it (even the middle of the numbered program lines) , and the ability to 
execute BASIC code that could be dumped into upper memory by the cpu in 
the floppy drive (which also gave the ability to execute variables). In short, 
GOTO can give you real inventive ways to get out of tight spots, and bypass 
long blocks of code. Same for long lists of tests on a variable, if it passes 
one test, no need to keep testing it, goto eotests and get on with it. GOTO 
can be a useful tool, rather like fire, to keep warm in emergencies, or 
misused, to burn garbage and give everyone downwind asthma. We don't 
outlaw the fire, we outlaw certain uses of it, like for burning garbage or
arson.
Likewise, GOTO can be restricted to targets inside the procedure or function 
it is invoked in, this should make implementing them easier too (at least in 
dos), since no one would write one procedure that is over a 64K memory 
block.

While the sequences in Eu are great, i can get by without them in mirc 
because mirc allows me to build var names, without pre-declaring them.

Running and tested mirc code for a scripted menu system, with built 
varnames and gotos:

Delete Exeption:{
    set -u0 %noi $$?="What number to delete?"
    if ( %noi == $null ) { goto eoDeleteExeption }
    if ( %noignore. [ $+ [ %noi ] ] == $null ) { 
      echo @NoIgnore 4 $atime -- Error, i cannot delete mask number %noi 
, it doesn't exist! --
      goto eoDeleteExeption 
    }
    echo @NoIgnore 2 --- $atime Deleting ---
    echo @NoIgnore 12 %noi : %noignore. [ $+ [ %noi ] ]
    echo @NoIgnore 2 -------
    set %noignore. [ $+ [ %noi ] ]
    :loopcompress
    if ( %noignore. [ $+ [ $calc(%noi + 1) ] ] != $null ) {
      set %noignore. [ $+ [ %noi ] ] %noignore. [ $+ [ $calc(%noi + 1) ] ]
      inc -u0 %noi 
      goto loopcompress
    }
    set %noignore. [ $+ [ %noi ] ]
    :eoDeleteExeption
  }

This:
%noignore. [ $+ [ %noi ] ] 
is like this:
sequence noignore
noignore[noi]

but in mirc, if %noi is out of bounds, there is no error, and i can build on 
more %noignore. [ $+ [ %noi ] ] just by specifying a new %noi index, 
including negative ones.

Tested and running mirc code:

Add Exemption:{
    set -u0 %noi 1
    :loopnoignore
    if ( %noignore. [ $+ [ %noi ] ] == $null ) {
      set %noignore. [ $+ [ %noi ] ] $$?="What mask to NoIgnore?"
      echo @NoIgnore 2 --- $atime Added ---
      echo @NoIgnore 12 %noi : %noignore. [ $+ [ %noi ] ]
      echo @NoIgnore 2 -------
      goto eoAddExemption
    }
    inc -u0 %noi
    goto loopnoignore
    :eoAddExemption
  }

Hence like i said 2 years ago, add in a few things mirc has, and Eu would 
beat the socks off it in *every way*. There are advantages to both mirc and 
Eu, but for most of my coding, i write far more mirc than Eu.

Kat

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

Search



Quick Links

User menu

Not signed in.

Misc Menu