lua-users home
lua-l archive

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


+1
This will also avoid further ambiguitiess with other (non-"local") statements that may come before.

Per variable annotation, prefixing each declared name is far preferable (also allows easier refactoring of existing source code, when modifiying existing declarations, especially when there are initializers at end of the variable list and an "=" sign, given that these initializers may also have their own annotations inside their _expression_).


Le lun. 10 juin 2019 à 18:31, Coda Highland <chighland@gmail.com> a écrit :


On Mon, Jun 10, 2019 at 10:19 AM szbnwer@gmail.com <szbnwer@gmail.com> wrote:
Roberto:
> Maybe I missed the answer, but repeating Dibyendu's question: How
to reconcile a syntax that prefixes an entire local statement with
per-variable annotations?

whats wrong with `local <const> a, b, <const> c, d`? do u mean that
`local <const> a, b, c, d` means by default that a-d are all
constants, so actually an opt-out would be needed for those that
shouldnt be constants?

if i understood u correctly, then i think the interpretation of my 2nd
_expression_ above just shouldnt make b-d constants; or i could think
about (with the `@` notation) this for making all vars constants:
`local @@const a, b, c, d` - so doubling the at symbol would extend
the range of the const from the 1st variable to all of them. this way
both needs are covered, and its really a visible thing to prevent
messing around stuffs like `a.b()` vs `a:b()` that took away some
happy time from all of us here not even once. :D (no offense for `:`,
basically im fine with it. :) )


Your thought there is fine. The question was about the suggestion to put the annotation BEFORE the "local" keyword. That syntax would essentially make it impossible to put both annotated and not-annotated variable declarations in the same statement; it would be all or nothing.

I think this particular issue is a good reason why the annotation should prefix the specific declaration being annotated instead of having it prefix the statement. Other languages just don't allow you to mix them in a single statement, but if that's a desirable feature in Lua then I don't think it's worth bikeshedding over the positioning.

/s/ Adam