[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: string.gsub and its need for variables..
- From: Philippe Lhoste <PhiLho@...>
- Date: Tue, 07 Sep 2004 09:56:43 +0200
(Again reading hundred of messages waiting in my Inbox, so answering to
Asko Kauppi wrote:
I -as many of the senior Lua citizens, I'm afraid- have been struck
_once_ by this. And that took some time..
As you said, it is unintuitive, and I wish we had a cure for it..
30.8.2004 kello 00:00, David Given kirjoitti:
The Doctor wrote:
Thankyou :) I like the brackets, that's a neat answer and the one
I'll use. The function is ok too, though I'd only do that if I wanted
further modification, probably. That said, isn't it strange that
there should be special requests for a minimum default? In most
things in life we might only want extra information if we ask for it,
and Lua, by doing the reverse of this, seems to risk losing the easy
and clarity it is so good at.
It's not a special request; gsub *always* returns multiple values. It's
just that if you just say x = string.gsub(...) then all except the first
one are discarded.
It just so happens that if a function that returns multiple values is
the last item in an argument list or a table definition, then all the
values are appended. If you'd done:
...then you would have seen the expected result (one string followed by
So Lua is behaving completely consistently, if a little unintuitively.
I don't agree with Asko here.
I was struck more than once by this problem ;-) but I never thought "Aw,
this language design is stupid" but instead "Ouch, I am stupid" :-P
I like this philosophy (returning as much info as possible/useful),
consistent as David says. Making gsub (and other functions like find)
returning only one parameter by default (the one we use the most) would
need another parameter (a flag) or something like that. It would add
some complexity, just to behave like a less capable language (C?)...
And if you don't like the way it behaves, it is so easy to create a new
function matching your need, I don't see why you complain :-)
-- (near) Paris -- France
-- Professional programmer and amateur artist
-- -- -- -- -- -- -- -- -- -- -- --