lua-users home
lua-l archive

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


On Sat, May 3, 2014 at 1:04 PM, Tim Hill <drtimhill@gmail.com> wrote:

> And in fact I agree that the back-quote syntax (or some equivalent) would have very little impact on compiler size or speed. I’m just nor sure about some of the other @string.byte() stuff, which starts to look a bit “heroic”.

The @function() for compile-time constant evaluation with constants
for arguments is an too risky/general -- I can't predict all the
pitfuls -- it was a nice daydream :-)

> So what you end up with is `a` being a compile-time shorthand for utf8.codepoint(“a”), which really doesn’t buy you much over calling the function and storing the code point in a local.

I believe you may be right, that `a` might not be worth it.  I was
writing an example to prove its merit and this doesn't really work
(forget for a moment that you can count characters with gsub()):

local count_char =
    function (s, c)
        local n = 0
        for x = 1, #s do
            if s[x] == `c` -- because this is evaluated at
compile-time only it would take the literal 'c', not the value of c at
runtime
                n = n + 1
            end
        end
        return n
    end

For situations where you know the character to take the codepoint
value of at compile-time, I still believe it would be friendlier than
writing:

local A = string.byte('a') -- because I come from C, it makes sense to
me to upcase identifiers of constants, but it can be confusing if
someone doesn't know you mean a or A

Furthermore this might shadow a variable at a higher scope, as it's
not a very specific identifier...

Anyway, I just wanted to say I do see your point. :-)