[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: require() parse error in 5.3.4/5.4.0-work2?
- From: Francisco Olarte <folarte@...>
- Date: Tue, 26 Jun 2018 13:32:07 +0200
On Tue, Jun 26, 2018 at 1:13 PM, Kenneth Lorber <email@example.com> wrote:
> Is there some reason this is a language feature? Some use-case I don't see? (If so, why is there the occasional check for extra arguments?)
There are reasons for not checking arguments by default in lua-like
languages, it makes some things easier. From the top of my head, I'm
presently using a single empty function as a default value for
callbacks in one of my systems ( so I just call them ). It is not
really neccessary, but it makes some things like that easier ( and may
be faster, but that is not the point ).
> Is it documented somewhere I missed?
In 3.4.11, more or less, with some examples.
Also, note checking for them in lua is difficult ( i.e., in f(a,b) is
not easy to differentiate a call as f(1,nil) from f(1) , or f(1,2,
nil) from f(1,2) ( I only know how to do it for the first case if I
just declare f(...) or f(a,b,...) for the second and check
table.unpack(...).n, but I'm not a guru, I only know how to do it in
C, but there all functions work like (...) )
In my code I normally just check where it makes sense (to me) and have
something nicer to do than not checking. Can think of an example now
and may be I haven,t got one in lua ( although the same problem
surfaces in Perl and I know I've done it there ).
> Is there any reason not to add checks for extra arguments? If it's performance, it could be available as a compile time option.
Besides superb speed, absent code is bug free, maintenance free and
size-optimized ( and this goes for the compile time option too,
remember lua can load() )