Re: byLine(n)?

2017-06-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 11, 2017 06:28:18 Stanislav Blinov via Digitalmars-d-learn wrote: > On Sunday, 11 June 2017 at 05:36:08 UTC, helxi wrote: > > I was writing a program that reads and prints the first nth > > lines to the stdout: > > > > import std.stdio; > > > > void main(string[] args) > > { > > >

Re: byLine(n)?

2017-06-11 Thread Cym13 via Digitalmars-d-learn
On Sunday, 11 June 2017 at 05:36:08 UTC, helxi wrote: I was writing a program that reads and prints the first nth lines to the stdout: import std.stdio; void main(string[] args) { import std.algorithm, std.range; import std.conv; stdin.byLine.take(args[1].to!ulong).each!writeln; }

Re: byLine(n)?

2017-06-11 Thread Cym13 via Digitalmars-d-learn
On Sunday, 11 June 2017 at 08:33:16 UTC, Cym13 wrote: On Sunday, 11 June 2017 at 05:36:08 UTC, helxi wrote: [...] Ok, if I read you right you are writing to stdin and want first to print the first args[1] lines, then to do other things with the other lines of stdin. [...] Meh... I just n

D, shared objects and MacOS

2017-06-11 Thread Russel Winder via Digitalmars-d-learn
Is the creation of shared objects still not possible on MacOS with: 1. DMD; 2. LDC2; 3. GDC. ? -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770

Re: D, shared objects and MacOS

2017-06-11 Thread Guillaume Piolat via Digitalmars-d-learn
On Sunday, 11 June 2017 at 09:53:09 UTC, Russel Winder wrote: Is the creation of shared objects still not possible on MacOS with: 1. DMD; 2. LDC2; 3. GDC. ? DMD: - possible with runtime disabled, all versions - or -betterC approach LDC: - possible with shared runtime dynlib IIRC sinc

Re: byLine(n)?

2017-06-11 Thread helxi via Digitalmars-d-learn
On Sunday, 11 June 2017 at 06:28:18 UTC, Stanislav Blinov wrote: On Sunday, 11 June 2017 at 05:36:08 UTC, helxi wrote: I was writing a program that reads and prints the first nth lines to the stdout: import std.stdio; void main(string[] args) { import std.algorithm, std.range; import

Re: byLine(n)?

2017-06-11 Thread Cym13 via Digitalmars-d-learn
On Sunday, 11 June 2017 at 12:44:05 UTC, helxi wrote: On Sunday, 11 June 2017 at 06:28:18 UTC, Stanislav Blinov wrote: On Sunday, 11 June 2017 at 05:36:08 UTC, helxi wrote: [...] You need only the nth line? Then you'd need to `drop` the preceding ones: void main(string[] args) { import

Re: byLine(n)?

2017-06-11 Thread helxi via Digitalmars-d-learn
On Sunday, 11 June 2017 at 12:49:51 UTC, Cym13 wrote: print each line byLine doesn't reall all input at once. Using byline and take you are effectively reading only the right amount of lines and not reading the rest. You already have what you want, what makes you think the contrary? Oh it w

Re: std.path.buildPath

2017-06-11 Thread Ryan Frame via Digitalmars-d-learn
On Sunday, 4 June 2017 at 18:15:36 UTC, Russel Winder wrote: On Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via Digitalmars-d- learn wrote: On 2017-06-04 07:44, Jesse Phillips wrote: > What is your expected behavior? Throw an exception? You can't > really > append an absolute path to another

Re: byLine(n)?

2017-06-11 Thread ag0aep6g via Digitalmars-d-learn
On 06/11/2017 03:00 PM, helxi wrote: I would also be really humbled if you demonstrate a faster approach of achieving the goal of the program :) (without explicitly using loops and conditions) Do you have a reason to believe that your version is slow? I don't see why it would be.

Re: How to implement opCmp?

2017-06-11 Thread Honey via Digitalmars-d-learn
On Friday, 9 June 2017 at 17:50:28 UTC, Honey wrote: Looking at the implementation of Tuple.opCmp, I'm not sure I'd bet on existence of opCmp for fundamental types: int opCmp(R)(R rhs) if (areCompatibleTuples!(typeof(this), R, "<")) { foreach (i, Unused; Type

Re: How to implement opCmp?

2017-06-11 Thread Honey via Digitalmars-d-learn
On Sunday, 11 June 2017 at 15:24:30 UTC, Honey wrote: Doesn't it make sense to introduce another overload of cmp similar to Steve's doCmp [2] right at that spot? Moreover, it seems that std.algorithm.cmp should employ three way comparison as well. The current implementation int cmp(alias pre

Re: How to implement opCmp?

2017-06-11 Thread Honey via Digitalmars-d-learn
On Sunday, 11 June 2017 at 15:40:42 UTC, Honey wrote: On Sunday, 11 June 2017 at 15:24:30 UTC, Honey wrote: Doesn't it make sense to introduce another overload of cmp similar to Steve's doCmp [2] right at that spot? Moreover, it seems that std.algorithm.cmp should employ three way comparison

First time user of LDC and getting newbie problems.

2017-06-11 Thread WhatMeForget via Digitalmars-d-learn
Just trying to compile a "Hello World" using dub and ldc2. The 32 bit works fine: generic@generic-ThinkPad-T61:~/Desktop/test$ dub run --compiler=ldc2 --arch=x86 Performing "debug" build using ldc2 for x86. test ~master: target for configuration "application" is up to date. To force a rebu

Re: brew install dmd

2017-06-11 Thread Joel via Digitalmars-d-learn
On Sunday, 11 June 2017 at 04:08:56 UTC, Seb wrote: But I'm not sure about doing this. This is a copy of the __official__ D installer as advertised on dlang.org (http://dlang.org/download.html): curl -fsS https://dlang.org/install.sh | bash -s dmd (the releases are signed) i.dlang.io is

O(1) sum

2017-06-11 Thread helxi via Digitalmars-d-learn
Is it possible to sum an array in O(1)?

Re: O(1) sum

2017-06-11 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 12 June 2017 at 01:02:58 UTC, helxi wrote: Is it possible to sum an array in O(1)? No. If you want to sum the elements you have to at-least look at all the elements. So it'll always be O(N). it's the best you can do.

Re: O(1) sum

2017-06-11 Thread Biotronic via Digitalmars-d-learn
On Monday, 12 June 2017 at 01:36:04 UTC, Stefan Koch wrote: On Monday, 12 June 2017 at 01:02:58 UTC, helxi wrote: Is it possible to sum an array in O(1)? No. If you want to sum the elements you have to at-least look at all the elements. So it'll always be O(N). it's the best you can do. On

Re: Is D slow?

2017-06-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 9 June 2017 at 19:43:55 UTC, Era Scarecrow wrote: On Friday, 9 June 2017 at 18:32:06 UTC, Steven Schveighoffer wrote: Wow, so that's how D code would look like if it were C++ :) When dipping my toes into C++ to do a quicksort algorithm, I quickly got annoyed I'd have to create all