* [EMAIL PROTECTED] <[EMAIL PROTECTED]> [2008-12-03 21:45]: > loop { > doSomething(); > next if someCondition(); > doSomethingElse(); > }
I specifically said that I was aware of this solution and that I am dissatisfied with it. Did you read my mail? * Jon Lang <[EMAIL PROTECTED]> [2008-12-03 20:10]: > Aristotle Pagaltzis wrote: > > * Bruce Gray <[EMAIL PROTECTED]> [2008-12-03 18:20]: > >> In Perl 5 or Perl 6, why not move the grep() into the > >> while()? > > > > Because it's only a figurative example and you're supposed to > > consider the general problem, not nitpick the specific > > example… > > But how is that not a general solution? You wanted something > where you only have to set the test conditions in one place; > what's wrong with that one place being inside the while()? Because readability suffers immensely when ensuring the invariant takes more than a single short expression. You have to break the loop condition out over several indented lines. Not pretty. * Eirik Berg Hanssen <[EMAIL PROTECTED]> [2008-12-03 22:30]: > I think Perl 5 will always allow: > > while ( doSomething(), someCondition() ) { > doSomethingElse(); > } > > I also think Perl 6 will always allow: > > while ( doSomething(); someCondition() ) { > doSomethingElse(); > } > > ... but don't quote me on that. Unless I'm right. ;-) The Perl 6 version of the two is more bearable, because neither do you need a `do{}` bracket nor do comma precendence issues force you to strew parens the expressions. But as I wrote above, this breaks down as soon as you need to do a non-trivial amount of work to ensure the invariant. * Jon Lang <[EMAIL PROTECTED]> [2008-12-03 22:05]: > I suspect that the difficulty with the while(1) version was the > kludgey syntax; the loop syntax that you describe does the same > thing (i.e., putting the test in the middle of the loop block > instead of at the start or end of it), but in a much more > elegant manner. The only thing that it doesn't do that a more > traditional loop construct manages is to make the loop > condition stand out visually. There’s no real difference between `while(1)` and `loop` to me. I don’t like C’s `for(;;)`, but both the Perl 5 and 6 idioms are equally fine with me. The problem I have is that the number of iterations is not indeterminate; there is a set amount of work to be complete, whereupon the loop will terminate. Contrast to the event loop in a GUI, f.ex., where the termination of the loop is an exceptional event, and the loop runs for as long as the app is running. This is much like being able to have statement modifier forms of conditionals and loops: I want to put emphasis on what matters. When I see `while ( @stuff )` that means to me that [EMAIL PROTECTED] is expected to run out as a consequence of the loop body operating on it. When I say `while (1)` I generally intend to say that I don’t expect the loop to terminate any time soon, although of course some uncommon condition might require termination. * David Green <[EMAIL PROTECTED]> [2008-12-03 22:00]: > On 2008-Dec-3, at 12:38 pm, Mark J. Reed wrote: >> I think the cleanest solution is the "coy" one. > > Me too. I don't think having the condition in the middle of the > block is necessarily a bad thing -- that's how the logic is > actually working, after all. Fake conditions like "while(1)" > are kind of ugly, but P6 has "loop", and you can always make it > stand out more: > > loop > { > doSomething(); > > #CHECK OUR LOOP CONDITION! > last unless someCondition; > > doSomethingElse(); > } See above. When each iteration of the loop reduces some finite quantity, I want to use a check for that quantity as the loop condition, to point out that this is the purpose of the loop: to finish a particular pile of work and terminate. This is in contrast to a loop which reacts to an infinite stream of input of whatever sort. Regards, -- Aristotle Pagaltzis // <http://plasmasturm.org/>