Pil3 clarification

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Pil3 clarification

Lorenzo Donati-3
Hi Roberto!

Reading PiL3 I noticed that you don't introduce the `select` function
when you talk about vararg functions.

However you use it in two places, namely p.203 in the snippet:

    count = select(2, string.gsub(str, " ", " "))

and at p.205:

    nvow = select(2, string.gsub(text, "[AEIOUaeiou]", ""))

Was it an intentional omission? One of those "dark corners of Lua"
mentioned in the preface (p.xvi) which PiL3 skips over?

If this is the case (then I wonder why - I thought it was the natural
way to process varargs) may I suggest to consider adding a line of
explanation before using `select`. IMHO the novice reader could be
really confused since the only `select` that was mentioned before was
Luasocket's select (p.95). It's not at all apparent that `select` is a
Lua base library function, so she could have an hard time guessing
what's happening.


Cheers!

-- Lorenzo

--
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

Reply | Threaded
Open this post in threaded view
|

Re: Pil3 clarification

Lorenzo Donati-3
Sorry for top-posting, but there is a reason for it.

I was looking in my personal mail Lua-l archive for something and I
stumbled on an old post of mine addressed to Roberto which never got an
answer.

After a brief investigation it appears that I sent that during the
"heat" of a Lua convention when Roberto & C. were abroad and probably
had not the time to even look into it.

Therefore I dare "bump" it, even though it might be obsolete now that
PiL4 is out (which I don't have, whereas I purchased PiL3 at the time).

If the new structure of PiL4 renders this utterly obsolete, please
accept my apology for the noise.

Anyway it boils down to: /is select function still a B-class citizen in
PiL4?/

Thanks


On 03/11/2013 11:32, Lorenzo Donati wrote:

> Hi Roberto!
>
> Reading PiL3 I noticed that you don't introduce the `select` function
> when you talk about vararg functions.
>
> However you use it in two places, namely p.203 in the snippet:
>
>     count = select(2, string.gsub(str, " ", " "))
>
> and at p.205:
>
>     nvow = select(2, string.gsub(text, "[AEIOUaeiou]", ""))
>
> Was it an intentional omission? One of those "dark corners of Lua"
> mentioned in the preface (p.xvi) which PiL3 skips over?
>
> If this is the case (then I wonder why - I thought it was the natural
> way to process varargs) may I suggest to consider adding a line of
> explanation before using `select`. IMHO the novice reader could be
> really confused since the only `select` that was mentioned before was
> Luasocket's select (p.95). It's not at all apparent that `select` is a
> Lua base library function, so she could have an hard time guessing
> what's happening.
>
>
> Cheers!
>
> -- Lorenzo
>

Reply | Threaded
Open this post in threaded view
|

Re: Pil3 clarification

Roberto Ierusalimschy
> Anyway it boils down to: /is select function still a B-class citizen in
> PiL4?/

PiL4 has an explanation about select somewhat similar to the one in
PiL2. However, it makes it clear that loops over varargs with select has
a cost that is quadratic with the number of arguments.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Pil3 clarification

Lorenzo Donati-3
On 22/05/2019 19:52, Roberto Ierusalimschy wrote:

>> Anyway it boils down to: /is select function still a B-class citizen in
>> PiL4?/
>
> PiL4 has an explanation about select somewhat similar to the one in
> PiL2. However, it makes it clear that loops over varargs with select has
> a cost that is quadratic with the number of arguments.
>
> -- Roberto
>
>
Thank you for the answer, Roberto!
This explains much. I didn't know it was /so/ costly (now I see why it
deserves the ugly functional syntax: it's a sort of warning sign).
So it turns out that for performing such a loop it's better to store the
varargs in a table {...} beforehand if performance is critical, isn't it?

On a related note, do you plan to improve the situation in Lua 5.4? That
is, changing the mechanism underlying varargs to improve performance?

The syntax turns out to be kinda weird, too. Maybe a change of syntax
with a new operator instead of a function call, with direct VM support
could improve the situation.

IIRC, please correct me if I'm wrong, you are not too fond of varargs,
but I find them very useful and expressive in some cases (of course,
like any powerful mechanism, you can easily shoot yourself in the foot,
if you are not careful), I'd be glad to see some improvement.

Cheers!

-- Lorenzo