[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: [ANN] metalua 0.4**
**From**: "Leo Razoumov" <slonik.az@...>
**Date**: Fri, 8 Feb 2008 07:00:48 -0500

On 2/8/08, Leo Razoumov <slonik.az@gmail.com> wrote:
> On 2/8/08, Fabien <fleutot+lua@gmail.com> wrote:
> > On Feb 8, 2008 12:56 AM, Leo Razoumov <slonik.az@gmail.com> 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.
I apologize for sloppy wording. The relevant sentence should read:
All Lua numbers share common metatable that can have "__index" method
properly handle this call and return a function (with one upvalue 9).
When called with arguments (1,3) this function will return table
{1,3,9}.
--Leo--