[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: fun with table constructors
- From: Reuben Thomas <rrt1001@...>
- Date: Tue, 30 Jan 2001 14:55:37 +0000 (GMT)
> But expressions beginning with brackets introduce ambiguity:
> The code above is parsed as a=b(f)(2) not as a=b;(f)(2).
> Some languages have a rule that newlines end statements if it makes sense to
> do so, but isn't that confusing too?
I use Lua as if it did, normally: I always put ; in when I have two
statements on the same line, and never when I have statements on different
lines. The difficult thing is that it must be possible to split a statement
Haskell has a "layout rule" which uses white space for nesting. This seems
to work well most of the time: the amount of space at the start of a line
determines the nesting level, by comparison with previous lines which have
the same amount of white space.
Lua doesn't need the full glory of layout, because it has explicitly
delimited blocks (in Haskell, you either use braces *or* the layout rule).
A simple rule that could work for Lua might be:
If a line starts with more white space than the previous one,
treat it as a continuation; otherwise treat it as a new statement.
To count white space, expand tabs to some number of spaces, and then just
count the total number of spaces. Or to avoid the tab-counting problem,
declare it a syntax error if the shorter line's initial white space is not a
prefix of the longer line's initial white space.
But it's a great pity that you can't write and immediately apply anonymous
http://sc3d.org/rrt/ | Caution Children At Play Drive Slowly