[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntactical ugliness - does it matter?
- From: Sean Conner <sean@...>
- Date: Tue, 4 Jun 2019 18:57:32 -0400
It was thus said that the Great Dibyendu Majumdar once stated:
> On Tue, 4 Jun 2019 at 21:24, Sean Conner <sean@conman.org> wrote:
> >
> > It was thus said that the Great Dibyendu Majumdar once stated:
> > >
> > > But more interestingly suppose you have a user defined type where the
> > > metatable has been registered. Suppose that the name under which you
> > > have registered the metatable is 'Torch.Tensor'.
> > >
> > > Then you can write:
> > >
> > > local x: Torch.Tensor = ...
> > > function Foo (x: Torch.Tensor)
> > > end
> >
> > Interesting. Can you handle the case where the user defined type has more
> > than just letters, digits and periods? I ask because I also use colons in
> > my user defined types, such as:
> >
> > org.conman.net:addr
> > org.conman.net:sock
> >
>
> At the moment, no. Each period separated component must be a Name -
> i.e. Lua identifier. So digits can appear within a name as per Lua
> rules. But ':' is problematic as I allow cast operations such as:
>
> local v = @Torch.Tensor SomeFuncReturningTensor()
>
> You can imagine that ':' here would cause a problem - i.e. should it
> be interpreted as a self operator?
>
> The chosen syntax is easy to handle with Lua's existing lexer and
> parser with some minor enhancements.
This even breaks with standard Lua, because of the following metatypes:
FILE* defined by the Lua io module
lpeg-pattern defined by LPEG
I suppose you could do:
local v = @['FILE*'] SomeFuncReturningFileObject()
given that foo.bar is syntactic surgar for foo['bar'].
-spc (Just a thought ... )