lua-users home
lua-l archive

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

On 2/8/08, Fabien <> wrote:
> On Feb 8, 2008 12:56 AM, Leo Razoumov <> wrote:
> >
> > How difficult is it to use MetaLua to augment Lua syntax with
> > Matlab/Octave matrix specific syntactic constructs.
> > For example, I would like to have something like that
> >
> > t={1:9:3} --> {1,3,6,9}  -- (inline iterative constructors)
> >
> However, your proposal will conflict with Lua syntax in many places:
> - ":" is the method invocation operator, which makes it hard to override
> after an expression

Well, I was suggesting Matlab-like syntax in spirit not in "letter".
Of course, if a certain Matlab construct directly conflicts with Lua
it can and should be replaced.
On the other hand this particular case of ":" operator can be handled
in Lua with a minor change. Here is one possibility:

Lua translates a:b(c) into  a[b](a,c). If one can make this rule to
include numbers as well we could have  1:9(3) to become 1[9](1,3). All
Lua numbers share common metatable that can have "__index" method
properly handle this call and return {1,3,9} table. IMHO, sequence
constructors in a form of 1:9(3) or 1:9() for default increment of 1
are already close enough to Matlab/Octave constructs 1:9:3 and 1:9.