lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Jamie Webb <j <at> jmawebb.cjb.net> writes:
> What does this mean: function print(x) print(y) end
> With your suggestion, we can't tell unless we know whether it's in an
> expression or statement context.

Yes, the need for context is a disadvantage.  Using a separate keyword
like "do" (as in the do patch) is one way to avoid that, but it's another
keyword.

> So what does 'f -123' mean?

The negative sign is troublesome as in -4^2, which is usually understood
as -16, having the negative separate from the number.  So, it might
actually mean 'f - 123' when, for data definition, the user might intend
it to mean 'f(-123)'.  That would not be good.

But similarly, I don't fully see why Lua allows parenthesis to be omitted
for string literals.  My guess is that it might be used for some syntactic
sugar as the Pythonic r"hello", treating r as some function that modifies
the string literal.

> What does 'print(x) print(y)' mean?

It would mean 'print(x)(print)(y)'.  However, this suggestion would clash
with Lua's allowance for statement separators, or even line breaks, to be
omitted.  So, that part is not as simple as it first seemed.