[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Feature request: plain option for gsub
- From: Coroutines <coroutines@...>
- Date: Fri, 22 Aug 2014 01:21:23 -0700
On Fri, Aug 22, 2014 at 1:04 AM, Axel Kittenberger <axkibe@gmail.com> wrote:
> Computationally speaking this would be like scratching ones head with the
> hand twisted three times around the head. Calculating a pattern just to
> parse it again to determine its just a simple string...
>
> I agree that an additional parameter for gsub is nonsense. A string:replace
> function would be sensible tough, since it skips all pattern matching. Don't
> tell me how one can build such function with match and string concatenation.
> I think everbody firm with coding knows, but wonders, why s/he has to
> reinvent this wheel once again.
>
> This issue viewed with from a step back, anything on Lua that begins with
> "feature request" is 100%ly to be shot down initially, with a 1% chance it
> might be picked up later anyway, when it is "invented here". Its the way
> that is.
>
> Two steps back: boils down to the disadvantage of Lua having language core
> and basic util library boiled together, where for the second a
> from-the-shelf string replace function would be desirable, while Lua gospel
> is, forget the shelf, you'll have to do everything on your own.
I still stand that an additional optional parameter to gsub would not
be total nonsense. Anyway, this whole thing has me thinking that I
wish "strings" did not exist in Lua. It's really just userdata and
sometimes I wish Lua didn't pool strings. I'd be much happier
creating a string pool manually if I intend to save on string
deduplication or copy-on-write situations. For a long time I've
wished Lua had more facilities for treating userdata like buffers --
with the ability to fill/write to them as needed and then promote them
to strings for pooling.
sorry, I'm getting off-topic again... I just wish we could have both.
I wish type('cat') returned userdata and I wish it were possible to
create mutable strings and promote them to pooled, specially handled
strings as needed. If we didn't have immutable, pooled strings by
default we could do less locking on the Lua state as well.
Okay, I'm gonna pack up my crazy now and head home :3
string.gsub(string, needle, repl, [plain [, n]]) would be easy to get
used to. My reasoning is that I almost never use the 'n' parameter
but there is a need. I imagine if plain replacements were available
in the form of another parameter it'd be more common, so it should
come first. You really wanna idea of how crazy things can be? Go
check out string.sub(), string.substr(), and string.substring() in
Javascript :p things could be a lot worse.