lua-users home
lua-l archive

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


On Sat, Dec 22, 2012 at 10:59 AM, Rena <hyperhacker@gmail.com> wrote:
> On Sat, Dec 22, 2012 at 1:40 PM, Grizzly Bear <6grizzlybear@gmail.com> wrote:
>> Thank you both! Problem solved.
>>
>>              tab.var@addr = 1
>>
>> is terser than
>>
>>              tab["var@addr"] = 1
>>
>> saving 3 chars and I'm a miser. That's why I liked to be able to do it.
>>
>> Wei
>>
>> On Wed, Dec 19, 2012 at 6:26 PM, Luiz Henrique de Figueiredo
>> <lhf@tecgraf.puc-rio.br> wrote:
>>>
>>> > But I haven't been able to do
>>> >           tab.var@addr = 1.
>>> >
>>> > I'm using Lua 5.1.5. Any suggestions?
>>>
>>> Not for 5.1, but in 5.2 you can tell the lexer that @ is a letter by
>>> editing lctype.c and rebuilding. Not that I recommend you to...
>>>
>>
>
> I had pondered before the idea of allowing '@' and '$' in names, at
> least at the beginning. That then led to the idea of functions named
> only @() and $(), which function like prefixes in that they don't need
> parentheses for a single argument, e.g.:
>
> $ = tostring
> x = {}
> print($x) --> prints "table: 0x......"
>
> The idea being mainly to avoid having to wrap things in tostring() and
> tonumber() everywhere, which gets ugly fast.
>
> --
> Sent from my Game Boy.
>

Personally I lean towards taking a tip from Scala, saying that any
character that isn't reserved for a known token is legal in
identifiers. Of course this means it becomes harder for the language
specification to ADD tokens...

/s/ Adam