Fw: Re: goto's, and loops
- Posted by Derek Parnell <dparnell at BIGPOND.NET.AU> Aug 15, 1999
- 477 views
-----Original Message----- From: Ralf Nieuwenhuijsen <nieuwen at xs4all.nl> To: Derek Parnell <dparnell at bigpond.net.au> Date: Friday, July 30 1999 03:42 Subject: Re: Re: goto's, and loops |I really wouldn't mind such a contruct to be added to Euphoria. |It allows exiting to block-constructs, but it the ability to name such a |construct also allows the interpreter to optimize the block as a whole, it |could allow for even more local variables and it would greatly improve the |readability for three reasons: | | 1) You don't have to comment the use of a block you _name_ it. | 2) You don't have to use exitflags | 3) You don't have to use goto | |Implementation-wise, I would suggest to allow to name each statements (great |for looking up in editors as well, the name is ignored by the interpreter, |unless its a loop construct, in which case you can use it to specify how |many levels to jump) | |And btw, consider the error message, (which is worth the trouble alone): | |" An error has occurding during tokenizing at line 123 " | |Example code: |-- Notice the fact that the whitespace function is not part of the other |routine because it |-- can be used much more often. Sometimes routines are a better choice, |sometimes they |-- are not. | |include common.e -- aka Eu-Upgrade-Library .. its at my site, webgen |needs it as well | |global function whitespace (sequence s) | return (s = ' ') + (s = '\n') + (s = '\t') + (s = '\r') |end function | |global function parse_file (sequence fname) |sequence tok, ct, mask |integer fh | | reading file: -- It is used as a comment here, but why not ? | fh = open (fname, "r") | if fh = NONE then | return NONE | end if | | init: tok = {} ct = "" mask = whitespace (cl) | tokenizing: for index = 1 to length (mask) do | | if mask[index] then | if length(ct) then | tok = append(tok, ct) | ct = "" | end if | else | ct = append(ct, cl[index]) | end if | | end tokenizing | | .. more code .. | |end function | |-------- | |I really do suspect this can help the interpreter optimizing. If it has to |slow down, or clean cache or whatever, which is not really needed |immediately, it can wait until the next 'named' part of code. In between, is |the best place for unnatural pauses. Rather than inside the loop construct |every now and so often. Also in windows, which I know is preemtive, it can |help keep the natural flow, for example by increasing the priority during |the block, and then releasing it at the end of such a block. It would then |never slow down during a draw procces, but inbetween, etc. timing can make |so much difference .. I think. | |Ralf N. |nieuwen at xs4all.nl | |[[ The elevator ]] |Http://www.xs4all.nl/~nieuwen | |Derek wrote: |> Another language I use, Progress 4GL, has a specialized variety of goto. |> It uses the syntax "leave <blockname>" . Your example would be coded |> thus... |> |> loop1: repeat: |> some code |> loop2: repeat: |> if var then leave loop1. |> end. /* of loop2 */ |> more code |> end. /* of loop 1 */ |> |> The idea of named blocks of code might not be too difficult it add to |> Euphoria, however name-space issues might arise. |> |> |> cheers, |> Derek Parnell |> dparnell at bigpond.net.au |> Melbourne, Australia |> | |