[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Most awesome string metatable hack
- From: Patrick Donnelly <batrick@...>
- Date: Sat, 1 Feb 2014 15:37:54 -0500
On Fri, Jan 31, 2014 at 10:00 AM, Andrew Starks <andrew.starks@trms.com> wrote:
>
> On Fri, Jan 31, 2014 at 6:33 AM, Fabien <fleutot+lua@gmail.com> wrote:
>>
>>
>>> print("hello %s" % { "world" }).
>
>
> Hmmm.... dangit!
>
> I like this better. Except for that it uses a table, but this is sweet. The
> extra parens kind of kill the syntactic beauty of the __call method. If not
> for that, it'd win in my book.
I think it would be an improvement if the % operator also accepted
closures in this case:
"Hello %s" % function() return "world" end
It's generally lighter weight than tables and, if you have closure
caching with unchanging upvalues, it can be constant cost.
--
Patrick Donnelly