[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: I'd give my right arm for a continue statement
- From: Dirk Laurie <dpl@...>
- Date: Thu, 27 Jan 2011 22:04:25 +0200
On Thu, Jan 27, 2011 at 06:42:13PM +0200, Roberto Ierusalimschy wrote:
> > > I believe that this "break N" will kill code readability as sure as
> > > "goto" would.
> > Yeah, I would get lost pretty quick! Named labels would help [...]
> If that could save Steve's right arm, we like the idea of break with
> In Lua, we cannot have traditional labels, because the syntax "foo:"
> already has a different meaning. Instead, a simple syntax would be to
> add labels only to "do end" blocks, for instance like this:
> do :label:
> Then, a continue could be written like here:
> while cond do
> do :process_item:
> break :process_item:
> There are several details that could change (other mark instead
> of colons, whether the label after break needs marks, whether an
> optional [or mandatory] label could be added after the corresponding
> 'end', etc.), but the basic idea would not change much.
You don't need that second colon. Since do, break and end are
keywords, do:foo, break:foo and end:foo can't be ambiguous.
Spaces around the first colon could be optional. Some might argue
that they improve readability.
I like the idea of other marks for break. Particularly, '<' and '>'.
break<foo -- resume just before end:foo (i.e. continue)
break>foo -- resume just after end:foo
This idea puts the emphasis on the label at 'end'; the label at
'do' seems not to be inevitable. I'd hate to debug programs that
don't have the 'do' labels, though. Those labels behave like
local declarations. So basically I support the idea that labels
should occur in pairs.
What about an optional label on 'end' that belongs to 'function'?
VIM does it by color :-) Or label pairs on then...end? No semantic
meaning, but useful for checking logic in a tortuous program.