lua-users home
lua-l archive

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


On 2015-08-24, at 12:07 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
> 
> On Fri, Aug 21, 2015 at 4:04 PM, Coda Highland <chighland@gmail.com> wrote:
>> I think C++11's way of defining new literals is pretty reasonable. You
>> define a suffix operator (which must start with _) and when literals
>> appear with that suffix, it's translated at compile time (in Lua's
>> case, bytecode generation time) to a call to that function
> 
> But (and this is crucial) any resulting object creation is not hoisted
> out. For instance, in languages with regexp literals /.../, the
> literal is replaced with a reference to a compiled regexp object.
> They effectively become constants.  If I see a 'date literal' like
> D'2015-08-24' in Lua I know that this string will be parsed _each
> time_ - it isn't really a literal.

The function will be called each time, which annoys me. But it is much cheaper than a parse:

https://stevedonovan.github.io/Penlight/api/libraries/pl.utils.html#memoize