lua-users home
lua-l archive

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

PA wrote:

Along the same line of though... I would rather see the colon notation deprecated all together... as it doesn't add anything which cannot be done with the regular syntax... plus it introduce inconsistency and confusion in Lua's core libraries... e.g. io seems to gratuitously favor the colon notation while all the other core libraries stick with the dot...

I have the exact opposite view. I want it to work for strings as well as tables. In fact, I want it to work with all types. I love the colon notation. This annoys me:

$ lua
Lua 5.0.2  Copyright (C) 1994-2003 Tecgraf, PUC-Rio
> s='10101111 10111010'
> print(s:len())
stdin:1: attempt to index global `s' (a string value)
stack traceback:
       stdin:1: in main chunk
       [C]: ?
> 67:print()
stdin:1: unexpected symbol near `67'

I like the way the colon notation removes redundant information from the code. Why should I have to write string.len(s)? I haven't looked at the parser - there may be good reasons why the last line above would be difficult - but I do not see why the parser should care what the type of the item before the ':' is. Just push it, then push the arguments to the function on the right of the colon, then look up and call the function on the right of the colon.

For example, I think this is much cleaner (bstring is C-based code that manipulates strings of bits):

$ lua
Lua 5.0.2  Copyright (C) 1994-2003 Tecgraf, PUC-Rio
> require'bstring'
>'10101111 10111010'
> print(s:len())
> g=s:golayencode()
> print(g:len())
> print(g)
> print(g:golaydecode())
101011111011    0
> print(g:bxor('10001')):golaydecode())
101011111011    2
> print(bstring.len(s) - bstring.len(bstring.golaydecode(g)))
> print(s:len() - g:golaydecode():len())

Short and sweet, and unambiguous. The last line is much cleaner than its predecessor, which lacks the colons.

Thank you for the colon notation! Please extend it to all types!


Doug Rogers - ICI - V:703.893.2007x220