lua-users home
lua-l archive

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


For the use case outside expressions, the "<" is supposed to be disambiguated by the previous token which is a reserved declarator token ("local" at start of a statement). If there was annotations to use in expressions, we would have then to prefix that notation with a declarator token.
I really don't see the interest of not using a common convention that just uses a single character.
Note that with the addition of the ">", it supposes that there may be parameters after the annotation token (only "toclose", or "const" for now). But I still see a use of such annotations inb expressions, notably for debugging info, optimization hints, floatting point evaluation mode (strict or relaxed mode, signaling or non-signaling NaNs, IEEE rounding mode...), control of parallelism or multithreading (relaxed or strict evaluation order of subexpressions, notably with function calls, or with operands of commutative or associative operations, or for allowing local declaration inside expressions with a limitation of scope (e.g in "(local a=1)+a": where does the scope of a terminates ?)

Controling the scope of "toclose" variables in expressions is also useful, to determine more precisely when the finalizer is allowed to run.

Or may be this can be controled by allowing blocks of instructions to have a return value, by enclosing them in parentheses and using the return statement at end of block, such as:
   x = (begin local a = 1; return a end) + 2 --[[ mostly equivalent  to x=3 ]].
In that case we can use statement starting with declarators like "local" optionnaly fowllowed by one or more annotations:
   x = (begin local <const> a = 1; return a end) + 2 --[[ mostly equivalent  to x=3 ]].


Le mer. 22 mai 2019 à 05:09, Sean Conner <sean@conman.org> a écrit :
It was thus said that the Great Dibyendu Majumdar once stated:
> The latest commits show the syntax <toclose> being adopted instead of *toclose.

  There's also <const> as well.  But you can't combine them:

        do
          local <toclose> f = io.open(foo)      -- okay
          local <const>   x = 5                 -- okay
          local <toclose> <const> g = io.open(bar) -- error
          local <const> <toclose> h = io.open(baz) -- also error
        end

> Aesthetically I find the new syntax to be nicer, but this still has
> the problem that the previous syntax had; which is that the symbol '<'
> has meaning in expressions therefore using this symbol (like the *
> symbol) may restrict the ability to use extensions inside expressions.
> Of course extensions will always be restricted to local declarations
> in which case it doesn't matter.

        do
          local *toclose f = io.open(foo)
          local *const   x = 5
        end

        do
          local @toclose f = io.open(foo)
          local @const   x = 5
        end

  Eh.  I tend to prefer the '@' syntax, but only because '@' has no current
use in Lua.  But I can live with this.

  But the latest manual for Lua 5.4 still mentions the old syntax.

  -spc