Ranges suck!
Brad Anderson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Sep 15 00:28:44 UTC 2017
On Thursday, 14 September 2017 at 23:53:20 UTC, Your name wrote:
> Every time I go to use something like strip it bitches and
> gives me errors. Why can't I simply do somestring.strip("\n")???
>
> import std.string would be the likely strip yet it takes a
> range and somestring, for some retarded reason, isn't a range.
> strip isn't the only function that does this. Who ever
> implemented ranges the way they did needs to get their head
> checked!
It's not really a range issue. It's that there are two strips.
One in std.string and one in std.algorithm. The latter which lets
you define what to strip rather than just whitespace is what you
are looking for and works as you've written. The former is there
for legacy reasons and we can hopefully get rid of it in the
future to avoid this confusion.
I'd also say that you don't seem to be grasping a pretty
fundamental D concept yet. std.string.strip doesn't take two
arguments, it takes one argument. The first set of parentheses is
the template argument which is inferred from the regular argument
using IFTI.
> [snip]
> Ok, so I know what your saying "Oh, but strip("\n") should be
> strip()! Your a moron RTFM!" But why then force me to strip for
> nothing? Why not pay me? e.g., let me strip for something like
> strip("x")?
strip()! isn't valid syntax. If you want to strip all whitespace
you can use std.string.strip (e.g., somestring.strip()). If you
want to strip "x" you can use std.algorithm.strip (e.g.,
somestring.strip("x")). Pretty much like any other language minus
the double function mess.
> Oh, chomp? Is that the function I'm suppose to use? Seriously?
> Was the D lib written by someone with a pacman fetish?
chomp comes to D by way of perl. I don't know whether or not
Larry Wall is into pacman or not.
More information about the Digitalmars-d-learn
mailing list