[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ambiguous Syntax
- From: "Peter Hill" <corwin@...>
- Date: Wed, 15 Jan 2003 02:18:33 +0800
Peter Hill:
> The only cases that require grouping are:
> (i) (function (a) ... end)(123)
> (ii) (<unop> x)(123)
> (iii) (x <binop> y)(123)
>
> Case (i) is important but, as I mentioned on the list a few days ago, the
> code can be converted to allow:
> function (a) ... end (123)
> by changing only a few lines.
(snip)
> Cases (ii) and (iii) are generally an error (unless there has been some
> metamethods at work, and even then things like (1+2)(Y) are pretty odd)
> the exception being the boolean operators which can easily return
> functions. For example "(fred or print)(123)".
RLake@oxfam.org.uk:
> But that is an important exception.
I guess I did do one of those 'or' of functions recently in my
Lua-parser-in-Lua code, although I just naturally assigned it to a local
variable for clarity so the issue didn't arise. Ie, I did:
scan = scan_lookup[token] or scan_other
b,t,x,l = scan(g,t,x,l)
> Another example is overloading binops to do things like functional
> composition, not uncommon at least in my code.
It's not? Do you have a few examples handy?
> A long time ago I pointed out on this list that the solution is really
> quite simple:
> function Do(x) return x end
> Do (table.move or default_move)(x, y)
> This doesn't *require* a language feature but it would be slightly more
> efficient if it had one. The word "Do" could be anything; do is a reserved
> word, but it pretty well encapsulated the meaning. If it were a language
> feature, it could also be an unambiguous unary operator such as !. Of
> course, it could also be called identity (it is, after all, just the
> identity function) but I don't think that leads to readable code.
Probably the most 'natural' identity/no-operation operator is '+', noting
that classically "+5" is the same as "5" (which appears in Lua as 1e+5 ==
1e5). I suppose that using the identity operator might be clearer in cases
needing leading parentheses? Eg:
+(fred or joe)(123)
A fudge, true, but something has to give somewhere... and the present
situation of having *one* special case of required ";" does seem to chafe
against the Lua principles, at least as far as I'm concerned.
There must (hopefully) be a neat solution somewhere.
*cheers*
Peter Hill.