Re: Goto (Was Re: Open Source)
- Posted by Juergen Luethje <j.lue at g?x?de> Oct 26, 2007
- 831 views
Pete Lomax wrote: > Juergen Luethje wrote: > > > > this is my translated code (untested): > > Your code worked perfectly on the second test set, and gave initially correct > answers on the first set, before yielding negative highvalues... > > I toyed with the idea of challenging you to find the bug > > The mistake you made is this: > > Pete Lomax wrote: > > > Try this then: > > > function find_combination(integer jumpToDa200) > > > if jumpToDa200 then goto da200 end if > > > da200:: > you translated this as: > > > > function find_combination(integer jumpToDa200) > > if not jumpToDa200 then > > end if > > while 1 do > > if not jumpToDa200 then > > end if > > if jumpToDa200 or flag = TRUE then > <da200:: was here> > > end if > > end while > > > The original jumped to da200 from the top of the routine, whereas you test the > parameter again on every iteration around the loop. Clearing the flag at the > point where the label used to be fixes it. I see. > From the number of tests it passed despite this flaw, I feel lucky to have > spotted it at all. > > > I created code for Matt's OOEU, which does support GOTO. Then I removed > > the GOTOs step by step and so in the end I had a program for the > > standard Eu interpreter. > Not really the answer though, installing two different interpreters, is it? Up to now, I have encountered this special problem only once. Since I registered Euphoria in April 2002, this means only once in 5+ years -- pretty much the same what you wrote. And in this rare situation I used an appropriate tool to solve the special problem. That was/is fine with me. What is the answer in your opinion? Regards, Juergen PS: IMHO it would be very cool if there were a kind of pre-processor, that could automagically translate GOTOs into more structured code. This would be a nice challenge for you and other "senior programmers", no? (I am curious whether this is actually possible from a theoretical point of view.)