lua-users home
lua-l archive

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


it's another way to use a distinctive prefix, but is it general ?

- Suppose you choose "in" (which is a already a reserved keyword in "for" statement, then you cannot use your extension after any variable listed between "for" and "in", even if this the "for" statement is a declaration of local variables: "for a<const> in pairs(...) do ... end" currently works (with drawbacks) to make the enumerated variable non modifiable inside the body of the loop; but it does not work with  "for a in const in pairs(...) do ... end"

Any reuse of existing keywords (or operator) must be checked in the existing syntaxic context where the keyword or operator is used: this was not done when choosing "< >" marks, that created shift-reduce conflicts in expressions, so it is also not a general extension mechanism.






Le dim. 24 mai 2020 à 19:39, Xavier Wang <weasley.wx@gmail.com> a écrit :
Andrea <andrea.l.vitali@gmail.com> 于2020年5月24日周日 上午1:55写道:
>
>
> Why <const> needs to be a suffix? could it be a prefix with respect to variable name?
> (this would allow to write something like "local const" which looks more natural).
>
> Is there a reason to have opening and closing mark? Or one could get away with something like !close or close! as Philippe was proposing?
>
> Actually I like the use of the exclamation mark as it draws attention to something peculiar.
> (I would use it for <close> which is really peculiar rather than <const> but anyway you get the idea)
>
> Thank you very much for all the answers and comments I got
>
>     Andrea
>
> --
> Andrea Vitali
>
>

Suffix means we can specify different attributes to every local
variables one line.

But I doubt the "<" and ">" symbol: Lua is a language that less use
symbols, we use "if ... then" but not "()", use "do ... end" but not
"{}". Only literals (tables) and expressions (operators) use symbols.
Maybe using an existing keyword for variable attributes is better?

like this:

function readall(filename)
   local fh in close = assert(io.open(filename))
   return thread "*a"
end

We just need change BNF from:
attrib ::= [‘<’ Name ‘>’]

To:
attire ::= ['in' Name]

e.g.
local pi in const = math.pi
local fh in close = assert(io.open(fn))
local const in const, handler in close = a, b

maybe "of" is a better word for keyword (I'm not native English
speaker ), but IMHO the keyword prefixed is better than the symbol
"<>".


--
regards,
Xavier Wang.