lua-users home
lua-l archive

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


On Mon, Jul 15, 2019 at 7:50 AM Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:

> May be the syntax should be more verbose (to correspond to overall language look-and-feel)?

As I said, the syntax I proposed is just one possibility.

> Such annotation might appear even in the middle of a Lua's grammar block 

I have realised that the semantics I proposed would have a problem in this case:

function(x, y, z) [a, b, c] end

Because it makes x, y, z inaccessible in the function's body, and having them repeat on the [] declaration would be ugly. A similar problem exists in the original proposal, too.

It could be solved by allowing [...] after the function keyword:

function[a, b, c](x, y, y) end

Then all of a, b, c, x, y, and z would be available within the function's body. If the function is named, then:

function [a, b, c]foo(x, y, y) end

which makes foo also available within the function. A syntax like function foo[a, b, c](x, y, z), which makes foo inaccessible within the function, is not necessary, because it would be equivalent to

foo = function[a, b, c](x, y, z)  end

In principle, this proposal makes the keyword function redundant, so, for example, a pure function could be unambiguously defined via []f(x, y, z) end  --:)

With respect to letting [...] (or its equivalent) appear anywhere in a block, I like the idea of annotating each syntactical block with its external dependencies at its start. This is why I find a terse syntax like [a, b,c ] acceptable, because it is always linked to some more verbose construct. External dependencies introduced in a middle of a block, not so much.

One final thing to consider is whether we would need a syntax to cancel all of those restrictions. An obvious candidate for this would be something like [*], but the question is whether it is really a good idea conceptually.

Cheers,
V.