lua-users home
lua-l archive

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


On Sat, May 3, 2014 at 5:42 AM, Petite Abeille <petite.abeille@gmail.com> wrote:

> "It would appear that Lua's clean syntax appeals to language improvers like a clean wall to graffiti sprayers."
> — David Kastrup, Sep 2010

This proposed sugar is evaluated once at compile-time, where every
appearance of string.byte() is always called at runtime.

Currently the best option is assigning the value to a local once, and
then using that local identifier throughout a loop.  It gets difficult
to figure out a name for these identifiers, though.  It also uses up 1
of the 200 afforded locals you have, but that's a lesser concern.

local A = string.byte 'a' -- too general
local LETTER_A = string.byte 'a' -- long identifier for where it would
appear, not very concise

It would help if we could put a literal integer value of 'a' there,
which makes a syntax other than '' and "" necessary for doing this
transform at compile-time.  I feel that it also makes the code more
readable than remembering what the identifier references.  Also this
value would then be read-only, as it would become a literal integer.

I've also pondered a syntax for having functions evaluated only at
compile-time if their operands are literal/static -- something like
@string.byte('a')

@ might later be used as an operator in some future major version of
Lua (so I consider this bad), but `` is unlikely to be, as it isn't
the traditional form of a single-char operator.

Is this a blind dislike of any additional syntax sugar that this list
is so well-known for?  Or do you see it colliding with future plans
for Lua?  I do think `` might be confused with '' if you're skimming
quickly -- that is a negativity.

"Posters on lua-l are as disagreeable as Republicans to Democrats."
-- Sir Pogsalot, Apr 2014

^ Things seem more profound in simile/quote-form.