lua-users home
lua-l archive

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


Arg! Yes but not within local declarations where such calls is illegal.
So we need another extension character for general extension purpose

Other punctuation characters in ASCII already have a meaning (and also used in digrams for other tokens):
 " # ' % ( )  * + , - . / : ; ^ < = > [ ] { } ~

There remains in the ASCII space only (still more than in C/C++/Java):
 ! $ & ? @ \ ` |

See:
 local x const! = 0; (because others don't like local x !const = 0;)
 local x $const = 0; (is the $ character allowed in identifiers? it seems not"Names (also called identifiers) in Lua can be any string of letters, digits, and underscores, not beginning with a digit.", but it is not part of ISO 646-IVS)
 local x &const = 0; or local x const& = 0; (not easy to type on many keyboards, and not part of ISO 646-IVS)
 local x ?const = 0; or  local x const? = 0;
 local x @const = 0; (though I would prefer keeping the @ for user-provided attributes and annotations, and it's not easy to type on many keyboards, and not part of ISO 646-IVS)
 local x \const = 0; (not easy to type on many keyboards, and not part of ISO 646-IVS)
 local x `const = 0; (not easy to type on many keyboards, and not part of ISO 646-IVS)
 local x |const = 0; (not easy to type on many keyboards, and not part of ISO 646-IVS)

The best candidates for general extension of the Lua language itself are then limited to '!' or '?'

If the prefix notation is prefered, then the best candidate is then '?'
  local x?const,  file?toclose, t = 10, open('filename'), [];

And for metatables pseudo-keys in table constructors or in get/set operations (with get still returning nil, but set creating a empty metatable when there's still none before setting a key):
  t = [10, 11, ? = [ type = 'something'] ]
  t[?].type2 = (t[?].type or nil) ..  ' else'

And for envuironment settings (replacing calls to fgetenv/fsetenv):
  fun?env = ...

The extensions decribed with the ? prefix allow the following extended tokens: ?, ?const, ?toclose, ?env, and many more for future versions of Lua, including additional operators like:

 ?<< or ?>> for binary rotations (could be named ?rol and ?ror instead)
 ?/ and ?% for modular euclidian divisions so that the modulo always has the same sign as the divisor and that also preserve the precision,
    where a?/b=floor(a/b) and a?%b= a-floor(a/b)*b (these could be named ?div and ?mod)
 (... ?? ... ?: ...) for a ternary conditional operator (these could be named ?if and ?else)
 ( ?| eval ?| cond1 ?|cond2 = value1 ?default = value2) (these could be named ?switch, ?case, ?default)

The extensions should be simple to parse: the ? prefix would be followed by another token (using the existing token syntax, possibly extended with a few operators that may be added like ` or |), but probably without allowing any space between them; the main difference is that all identifiers that follow the ? are reserved for the language and not used for any variable name declared in user-space.

User-annotations using @ are still a common convention and no one complained if they had to type it with AltGr+key.

But pairs with '<' and '>' are among the worst as it has limited usage in specific syntaxic constructs (and cause difficulties in parsers with shift-reduce problems).


Le lun. 25 mai 2020 à 11:43, pocomane <pocomane_7a@pocomane.com> a écrit :
On Mon, May 25, 2020 at 10:21 AM Ray <emacsray@gmail.com> wrote:
> On every discussion thread I can find about 5.4 <const> <close>, there
> are great piles of complaints about the horrible syntax.
> Hope the syntax can still be fixed, otherwise it will assuredly hamper
> the adoption.

Not for 5.4, I do not think so.

> Oh, does `x:const = 1` imply `local`? This syntax seems nice!

Yes but it is not possible since it already means something in lua
(call the const method of x). I did not realize this when I made my
previous examples, sorry.