[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: unexpected syntax error
- From: Rob Kendrick <rjek@...>
- Date: Wed, 28 Nov 2012 16:21:35 +0000
On Wed, Nov 28, 2012 at 05:17:28PM +0100, Matthias Kluwe wrote:
> Hi!
>
> I played around trying to create a small DSL and stumbled upon an
> unexpected behaviour. This is a small example:
>
> local function f()
> return setmetatable( {}, {
> __div = function( t, arg )
> print( arg )
> end } )
> end
>
> f{} / 'a'
That's because this is an expression, not a statement. It doesn't work
as f() / 42, either. You need to specify where to put the result, or
use it in a flow control structure.
> I get the error message "unexpected symbol near '/'".
>
> Surprisingly, the following prints 'a':
>
> (function() end)( f{} / 'a' )
Not to me: this is a statement that calls a function, passing in the
result of an expression.
B.