lua-users home
lua-l archive

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



Em 06/06/2015 23:10, "Rena" <hyperhacker@gmail.com> escreveu:
>
> On Sat, Jun 6, 2015 at 5:33 PM, Rodrigo Azevedo <rodrigoams@gmail.com> wrote:
> > 3.4.10 – Function Calls
> >
> > The form
> >
> > functioncall ::= prefixexp ‘:’ Name args
> >
> > Arguments have the following syntax:
> >
> > args ::= ‘(’ [explist] ‘)’
> > args ::= tableconstructor
> > args ::= LiteralString
> >
> > can be used to call "methods". A call v:name(args) is syntactic sugar for
> > v.name(v,args), except that v is evaluated only once.
> >
> > -------------------
> >
> > Let v be a usardata with a unary method, then
> >
> > v:abs() is a syntatic sugar for v.abs(v)
> > v:reduce() is a syntatic sugar for v.reduce(v)
> >
> > etc
> >
> > This notation is very unpleasant. There is a problem if this behaviour of
> > function calls
> >
> > v:abs is a syntativ sugar for v.abs(v)
> > v:reduce is a syntatic sugar for v.reduce(v)
> >
> > was valid?
> >
> > If not, I really appreciate this new flavor.
> >
> > --
> > Rodrigo Azevedo Moreira da Silva
>
> You want `v:abs` to mean the same as `v.abs(v)`? That seems a bit
> unusual.

I agree with unusual, based also on discussions with other programmers I had. But I think

v:f"string"
and
v:f{b,c}

as unusual. I think this is only a matter of definition and convenience, namely, the place of syntactic sugar.

What I've seen in some dialects is that it automatically
> creates a closure; i.e. `f = v:abs` means the same as `f =
> function(...) return v:abs(...) end`.
>
> --
> Sent from my Game Boy.
>