June 09, 2014 Re: splitter for strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | On Monday, 9 June 2014 at 18:09:07 UTC, monarch_dodra wrote:
> On Monday, 9 June 2014 at 17:57:24 UTC, Steven Schveighoffer wrote:
>> I think we are confusing things here, I was talking about strip :)
>
> strip and split are actually both pretty much in the same boat actually in regards to that, so just 's/split/strip/g', and the same answer will apply.
>
> "split" (and "splitter") actually have it a bit more complicated, because historically, if you imported both string and algorithm, then "split(myString)" will create an ambiguous call. The issue is that you can't do selective imports when you already have a local object with the same name, so algorithm had:
>
> ----
> auto split(String)(String myString) {
> return std.string.split(myString);
> }
> ----
> rather than
> ----
> public import std.string : split;
> ----
>
> I tried to "fix" the issue by removing "split(String)" from algorithm, but that created some breakage.
>
> So Andrei just came down and put *everything* in algorithm, and added an "public import std.algorithm : split" in std.string.
>
> This works, but it does mean that:
> 1. string unconditionally pulls algorithm.
> 2. You can do things like:
> std.string.split([1, 2, 3], 2);
>
> IMO, the "strip" solution is better :/
>
>> If we could split up std.algorithm into individual modules, that would probably help.
>>
>> -Steve
>
> Yes.
I think it makes sense to put any generic range based algorithms (split and so forth) into std.algorithm. It's always my first port of call, when I have a range. However, that you can do
std.string.split([1, 2, 3], 2);
is not exactly a desirable situation.
|
June 09, 2014 Re: splitter for strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris | On Monday, 9 June 2014 at 19:47:29 UTC, Chris wrote:
> Uh, I see, I misread the signature of std.string.strip(). So that's one option now, to strip all trailing hyphens with std.string.strip(). Well, I'll give it a shot tomorrow.
No, you read the documentation of std.*STRING*.strip correctly.
I'm suggesting you use the one from std.*ALGORITHM*.
The signatures are mutually exclusive, so you don't need to qualify them.
|
June 09, 2014 Re: splitter for strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris | On Monday, 9 June 2014 at 19:54:08 UTC, Chris wrote:
> I think it makes sense to put any generic range based algorithms (split and so forth) into std.algorithm. It's always my first port of call, when I have a range. However, that you can do
>
> std.string.split([1, 2, 3], 2);
>
> is not exactly a desirable situation.
Right, but "split(hello world)" *is* string specific. It makes sense for strings only. It doens't make sense to write "split([1, 2, 3])", which is why I'm unsatisfied with the current situation.
|
June 09, 2014 Re: splitter for strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | On Monday, 9 June 2014 at 20:01:05 UTC, monarch_dodra wrote:
> On Monday, 9 June 2014 at 19:47:29 UTC, Chris wrote:
>> Uh, I see, I misread the signature of std.string.strip(). So that's one option now, to strip all trailing hyphens with std.string.strip(). Well, I'll give it a shot tomorrow.
>
> No, you read the documentation of std.*STRING*.strip correctly.
>
> I'm suggesting you use the one from std.*ALGORITHM*.
>
> The signatures are mutually exclusive, so you don't need to qualify them.
Ah, ok, talking about not seeing the forest for the trees ...
|
Copyright © 1999-2021 by the D Language Foundation