[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string[], doesn't exist?
- From: "Aaron Brown" <arundelo@...>
- Date: Fri, 23 Jun 2006 14:10:26 -0400
Anders Bergh wrote:
That's bad... ("foo"):len() looks weird.
It's not just a special case, though. It's a bit of syntax
that applies to other things too: anytime something other
than a variable name or a function call is used before
square brackets, a dot, an argument list, or a colon, it
needs to be surrounded in parentheses. (This turns it into
a "prefixexp" -- see the syntax chart at the end of the
manual.)
> =({"foo", "bar"})[2]
bar
> =({foo = true}).foo
true
> =(function(A, B) return A + B end)(2, 2)
4
> =({fun = function(self, argu) return self, argu end}):fun("Hi")
table: 0x493be0 Hi
I believe the purpose (or one purpose) of this is to
minimize dependence on newlines for parsing. If it wasn't
necessary, then
fun "foo" "bar" "baz"
"quux":meth()
would have to parse differently from either
fun "foo" "bar" "baz" "quux":meth()
or
fun "foo" "bar" "baz";
"quux":meth()
By the way, if you've never seen the 'fun "foo" "bar" "baz"'
syntax before, here's an example of it:
> function fun(s)
>> print(s)
>> return fun
>> end
> fun "foo" "bar" "baz"
foo
bar
baz
--
Aaron
- References:
- Bitwsie operators in Lua, mike krimerman
- Re: Bitwsie operators in Lua, Andy Stark
- Re: Bitwsie operators in Lua, Doug Rogers
- Re: Bitwsie operators in Lua, Andy Stark
- Re: Bitwsie operators in Lua, Roberto Ierusalimschy
- string[], doesn't exist?, Sam Roberts
- Re: string[], doesn't exist?, Luiz Henrique de Figueiredo
- Re: string[], doesn't exist?, Sam Roberts
- Re: string[], doesn't exist?, Diego Nehab
- Re: string[], doesn't exist?, Vyacheslav Egorov
- Re: string[], doesn't exist?, Anders Bergh