findBack: find a needle in a haystack from the back

2014-06-09 Thread Timothee Cour via Digitalmars-d-learn
Is there a more idiomatic/elegant way to achieve the following, while remaining as efficient as possible? Same question in the simpler case n==0? using retro seems inefficient because of all the decodings // returns the largest suffix of a that contains no more than n times c string

splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
Say I wanna split a string that contains hyphens. If I use std.algorithm.splitter I end up with empty elements for each hyphen, e.g.: auto word = bla-bla; auto parts = appender!(string[]); w.splitter('-').copy(parts); // parts.data.length == 3 [bla, , bla] This is not ideal for my purposes,

Re: splitter for strings

2014-06-09 Thread bearophile via Digitalmars-d-learn
Chris: auto word = bla-bla; auto parts = appender!(string[]); w.splitter('-').copy(parts); // parts.data.length == 3 [bla, , bla] With the current dmd 2.066alpha this code: void main() { import std.stdio, std.string, std.algorithm; const txt = bla-bla; txt.split(-).writeln;

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 10:14:40 UTC, bearophile wrote: Chris: auto word = bla-bla; auto parts = appender!(string[]); w.splitter('-').copy(parts); // parts.data.length == 3 [bla, , bla] With the current dmd 2.066alpha this code: void main() { import std.stdio, std.string,

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote: Ok, thanks. I'll keep that in mind for the next version. Seems to me to also work with 2.065 and 2.064.

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote: Ok, thanks. I'll keep that in mind for the next version. Seems to me to also work with 2.065 and 2.064. From the library reference: assert(equal(splitter(hello world, ' '), [

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote: From the library reference: assert(equal(splitter(hello world, ' '), [ hello, , world ])); and If a range with one separator is given, the result is a range with two empty elements. My problem was that if I have input like auto word

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote: From the library reference: assert(equal(splitter(hello world, ' '), [ hello, , world ])); and If a range with one separator is given, the result is a range with two empty

Re: findBack: find a needle in a haystack from the back

2014-06-09 Thread Tobias Pankrath via Digitalmars-d-learn
On Monday, 9 June 2014 at 07:58:25 UTC, Timothee Cour via Digitalmars-d-learn wrote: Is there a more idiomatic/elegant way to achieve the following, while remaining as efficient as possible? Same question in the simpler case n==0? using retro seems inefficient because of all the decodings //

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 11:40:24 UTC, Chris wrote: On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote: From the library reference: assert(equal(splitter(hello world, ' '), [ hello, , world ])); and If a range with one

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 12:16:30 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 11:40:24 UTC, Chris wrote: On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote: From the library reference: assert(equal(splitter(hello world,

Re: splitter for strings

2014-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 09 Jun 2014 07:04:11 -0400, Chris wend...@tcd.ie wrote: On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote: Ok, thanks. I'll keep that in mind for the next version. Seems to me to also work with 2.065 and 2.064. From

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 07:04:11 -0400, Chris wend...@tcd.ie wrote: On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote: Ok, thanks. I'll keep that in mind for the

Re: splitter for strings

2014-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 09 Jun 2014 10:39:39 -0400, Chris wend...@tcd.ie wrote: Atm, I have auto parts = appender!(string[]); w.splitter('-').filter!(a = !a.empty).copy(parts); Which looks more elegant and gives me what I want. IMO, the module that handles the splitting of hyphenated words should be able

win64 as orphan?

2014-06-09 Thread trail via Digitalmars-d-learn
will the sorry state of the win64 headers and programs like dfl be fixed or is it time to leave the language to linux and move on to something else?

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 10:39:39 -0400, Chris wend...@tcd.ie wrote: Atm, I have auto parts = appender!(string[]); w.splitter('-').filter!(a = !a.empty).copy(parts); Which looks more elegant and gives me what I want. IMO, the

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer wrote: Just looked at std.string for a strip function that allows custom character strippage, but apparently not there. The above is quite awkward. -Steve It's in algorithm, because it's more generic than just strings.

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 15:19:05 UTC, Chris wrote: On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 10:39:39 -0400, Chris wend...@tcd.ie wrote: Atm, I have auto parts = appender!(string[]); w.splitter('-').filter!(a = !a.empty).copy(parts); Which

hijacking override from template mixin

2014-06-09 Thread Ivan Kazmenko via Digitalmars-d-learn
The D language pays certain attention to avoiding hijacking [1]. So I was surprised when I hijacked a function override from a template mixin by mistake. Here is a commented example. The comments explain the relevant part of the life cycle of the program. - // Start with class A with

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 15:54:29 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 11:49:29 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer wrote: Just looked at std.string for a strip function that allows custom character

Re: hijacking override from template mixin

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 9 June 2014 at 15:54:21 UTC, Ivan Kazmenko wrote: I'd expect a multiple overrides of same function error, much like if I just paste the mixin code by hand. Is that a bug or working by design? In the latter case, please explain the reasoning. AFAIK, the rationale is that *should*

Re: win64 as orphan?

2014-06-09 Thread lurker via Digitalmars-d-learn
i agree with you, but you should have posted in announce, so that adrei can use it for some marketing. i too wait now for a long, long time to use it with win64. i am also giving up - i guess it will stay a linux/apple show. maybe, as a multiple os compiler, you can use lazarus or code typhon.

Re: findBack: find a needle in a haystack from the back

2014-06-09 Thread Nordlöw
using retro seems inefficient because of all the decodings Phobos git master just got support for next-gen string processing: https://github.com/D-Programming-Language/phobos/pull/2043 I believe x.byChar.retro is what you want

DMD Compiler Version Dependent Conditional Compilation

2014-06-09 Thread Nordlöw
Can I use the version keyword or static if to perform conditional compilation that depends on the version of DMD? I typicall something like version(= DMD_2.0.66) { // use new byChar, byWchar, byDchar, byCodepoint } else { // use old style slower version } If so how?

Re: DMD Compiler Version Dependent Conditional Compilation

2014-06-09 Thread David Nadlinger via Digitalmars-d-learn
On Monday, 9 June 2014 at 17:36:10 UTC, Nordlöw wrote: Can I use the version keyword or static if to perform conditional compilation that depends on the version of DMD? The __VERSION__ magic token should do the job. David

Re: DMD Compiler Version Dependent Conditional Compilation

2014-06-09 Thread Nordlöw
Thx

Re: splitter for strings

2014-06-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 09 Jun 2014 12:06:13 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Monday, 9 June 2014 at 15:54:29 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 11:49:29 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
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.

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
On Monday, 9 June 2014 at 15:52:24 UTC, monarch_dodra wrote: On Monday, 9 June 2014 at 15:19:05 UTC, Chris wrote: On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer wrote: On Mon, 09 Jun 2014 10:39:39 -0400, Chris wend...@tcd.ie wrote: Atm, I have auto parts =

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
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

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
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.

Re: splitter for strings

2014-06-09 Thread monarch_dodra via Digitalmars-d-learn
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

Re: splitter for strings

2014-06-09 Thread Chris via Digitalmars-d-learn
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,

enum template shorthand and short circuit evaluation

2014-06-09 Thread Byron via Digitalmars-d-learn
Should this work? It seems like the short circuit booleans are not working: import std.traits; enum isPrimitive(T) = isBasicType!T || (isArray!T isBasicType! (ForeachType!T)); void main() { assert(isPrimitive!int); assert(isPrimitive!char);