Re: ushort calls byte overload

2017-05-30 Thread Daniel Kozak via Digitalmars-d-learn
Dne 30.5.2017 v 23:16 Oleg B via Digitalmars-d-learn napsal(a): Hello. I have this code import std.stdio; void foo(byte a) { writeln(typeof(a).stringof); } void foo(short a) { writeln(typeof(a).stringof); } void foo(int a) { writeln(typeof(a).stringof); } void main() { foo(0); // int,

Re: howto count lines - fast

2017-05-30 Thread Daniel Kozak via Digitalmars-d-learn
I do not know this is my first attempt and it is almost same fast as wc on my pc: int main(string[] args) { import std.stdio : writeln, writefln, File; import std.array : uninitializedArray; auto f = File("data"); size_t c = 0; auto buffer =

howto count lines - fast

2017-05-30 Thread Nitram via Digitalmars-d-learn
After reading https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ , i was wondering how fast one can do a simple "wc -l" in D. So i made a couple short implementations and found myself confronted with slow results compared to "/usr/bin/wc -l". How would a implementation look

Re: howto count lines - fast

2017-05-30 Thread Jordan Wilson via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 20:37:44 UTC, Jordan Wilson wrote: On Tuesday, 30 May 2017 at 20:02:38 UTC, Nitram wrote: After reading https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ , i was wondering how fast one can do a simple "wc -l" in D. So i made a couple short

Re: ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn
and this is unexpected for me too immutable ushort y = 0; foo(y); // byte

ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn
Hello. I have this code import std.stdio; void foo(byte a) { writeln(typeof(a).stringof); } void foo(short a) { writeln(typeof(a).stringof); } void foo(int a) { writeln(typeof(a).stringof); } void main() { foo(0); // int, and byte if not define foo(int) foo(ushort(0)); // byte

Re: howto count lines - fast

2017-05-30 Thread Jordan Wilson via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 20:02:38 UTC, Nitram wrote: After reading https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ , i was wondering how fast one can do a simple "wc -l" in D. So i made a couple short implementations and found myself confronted with slow results compared

Re: howto count lines - fast

2017-05-30 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 23:41:01 UTC, H. S. Teoh wrote: This little challenge piqued my interest. So I decided to take a shot at seeing if I could beat my system's /usr/bin/wc -l. First order of business: whenever it comes to performance, always choose the right compiler for the job...

Re: Rosetta Commatizing numbers

2017-05-30 Thread Jordan Wilson via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:54:49 UTC, Solomon E wrote: The earlier version of the page made D look more error prone than other languages, but short. Now my solution is as long as some of the other language's solutions, but it's well commented and tested, I think. Now I doubt any of the

Re: howto count lines - fast

2017-05-30 Thread H. S. Teoh via Digitalmars-d-learn
P.S. After I posted the code, I took a closer look at the disassembly and found that gdc wasn't generating the best code for the parallel foreach loop body. I haven't fully traced the cause yet, but I did find a simple optimization (arguably a micro-optimization): updating the subtotal inside the

Re: howto count lines - fast

2017-05-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 30, 2017 at 08:02:38PM +, Nitram via Digitalmars-d-learn wrote: > After reading > https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ , i > was wondering how fast one can do a simple "wc -l" in D. > > So i made a couple short implementations and found myself

Re: howto count lines - fast

2017-05-30 Thread Ali Çehreli via Digitalmars-d-learn
On 05/30/2017 01:02 PM, Nitram wrote: After reading https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ , i was wondering how fast one can do a simple "wc -l" in D. So i made a couple short implementations and found myself confronted with slow results compared to "/usr/bin/wc -l".

Re: binding to C++

2017-05-30 Thread Oleksii via Digitalmars-d-learn
On Friday, 26 May 2017 at 15:17:08 UTC, drug wrote: Trying to bind to cpp code I stop at some moment having undefined reference to some cpp function. But objdump -Ct cpplibrary.so shows me that this cpp function exists in the library. linker message about cpp function is _identical_ to

Re: purity question

2017-05-30 Thread Rene Zwanenburg via Digitalmars-d-learn
On Monday, 29 May 2017 at 01:36:24 UTC, Jonathan M Davis wrote: A simple example: anything that has a malloc/free pair. Yeah, if you do it right, you should be fine, but you have to do it right, and it's very easy to miss some detail that makes it wrong to insist to the compiler that what

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Andrew Edwards via Digitalmars-d-learn
Sorry, rough day. Could someone please explain what this means and how do go about resolving it? Thanks, Andrew

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:09:50 UTC, Andrew Edwards wrote: What does that even mean? Scenario: bool func(const ImVec2 label_size) { return true; } void main() { //first attempt: const ImVec2 label_size = CalcTextSize(label.ptr, null, true); //Error: cannot implicitly

Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Andrew Edwards via Digitalmars-d-learn
What does that even mean? Scenario: bool func(const ImVec2 label_size) { return true; } void main() { //first attempt: const ImVec2 label_size = CalcTextSize(label.ptr, null, true); //Error: cannot implicitly convert expression (CalcTextSize(cast(immutable(char)*)label, null,

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Daniel Kozak via Digitalmars-d-learn
It seems there are two different ImVec2 types. So ImVec2 is not same as ImVec2 :) On Tue, May 30, 2017 at 12:09 PM, Andrew Edwards via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > What does that even mean? > > Scenario: > > bool func(const ImVec2 label_size) > { > return

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:31:24 UTC, Daniel Kozak wrote: import std.traits : fqn = fullyQualifiedName; Darnit. I just googled the template and got a result talking about fqn!T. So yeah - this code: import std.traits; pragma(msg, fullyQualifiedName!ImVec2); pragma(msg,

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:46:12 UTC, Andrew Edwards wrote: On Tuesday, 30 May 2017 at 10:37:58 UTC, Biotronic wrote: On Tuesday, 30 May 2017 at 10:31:24 UTC, Daniel Kozak wrote: import std.traits : fqn = fullyQualifiedName; Darnit. I just googled the template and got a result talking

Re: purity question

2017-05-30 Thread ketmar via Digitalmars-d-learn
Rene Zwanenburg wrote: On Monday, 29 May 2017 at 01:36:24 UTC, Jonathan M Davis wrote: A simple example: anything that has a malloc/free pair. Yeah, if you do it right, you should be fine, but you have to do it right, and it's very easy to miss some detail that makes it wrong to insist to

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:20:53 UTC, Andrew Edwards wrote: Sorry, rough day. Could someone please explain what this means and how do go about resolving it? Thanks, Andrew If you want to resolve it just do const label_size = CalcTextSize(...); but as others have mentioned make sure

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Andrew Edwards via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:37:58 UTC, Biotronic wrote: On Tuesday, 30 May 2017 at 10:31:24 UTC, Daniel Kozak wrote: import std.traits : fqn = fullyQualifiedName; Darnit. I just googled the template and got a result talking about fqn!T. So yeah - this code: import std.traits;

Rosetta Commatizing numbers

2017-05-30 Thread Solomon E via Digitalmars-d-learn
I ran into a Rosetta code solution in D that had obvious errors. It's like the author or the previous editor wasn't even trying to do it right, like a protest against how many detailed rules the task had. I assumed that's not the way we want to do things in D. Then I spent all day fixing it.

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Daniel Kozak via Digitalmars-d-learn
http://forum.dlang.org/post/xpmpakmusudanwuzz...@forum.dlang.org https://issues.dlang.org/show_bug.cgi?id=9631 On Tue, May 30, 2017 at 1:07 PM, Biotronic via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 30 May 2017 at 10:46:12 UTC, Andrew Edwards wrote: > >> On

Re: Best way for handle missing args in REST interface in vibed

2017-05-30 Thread Suliman via Digitalmars-d-learn
I had post question here http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/43511/

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Daniel Kozak via Digitalmars-d-learn
import std.traits : fqn = fullyQualifiedName; On Tue, May 30, 2017 at 12:24 PM, Biotronic via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 30 May 2017 at 10:09:50 UTC, Andrew Edwards wrote: > >> What does that even mean? >> >> Scenario: >> >> bool func(const

Re: ushort calls byte overload

2017-05-30 Thread nkm1 via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 21:16:26 UTC, Oleg B wrote: Hello. I have this code import std.stdio; void foo(byte a) { writeln(typeof(a).stringof); } void foo(short a) { writeln(typeof(a).stringof); } void foo(int a) { writeln(typeof(a).stringof); } void main() { foo(0); // int, and byte if

Re: Rosetta Commatizing numbers

2017-05-30 Thread Ivan Kazmenko via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:54:49 UTC, Solomon E wrote: I ran into a Rosetta code solution in D that had obvious errors. It's like the author or the previous editor wasn't even trying to do it right, like a protest against how many detailed rules the task had. I assumed that's not the way we

Re: Rosetta Commatizing numbers

2017-05-30 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 31 May 2017 at 04:31:14 UTC, Ivan Kazmenko wrote: Now, where is the old version wrong? ... Actually, it also changes every number in the string, not only the first one as required. Because of that, it also fails the "do not touch the exponent" requirement. Sadly, both are

Re: purity question

2017-05-30 Thread ketmar via Digitalmars-d-learn
Rene Zwanenburg wrote: On Tuesday, 30 May 2017 at 11:34:52 UTC, ketmar wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? of course. but D "pure" is not what other world knows as "pure". we love to mess with

Re: purity question

2017-05-30 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 11:34:52 UTC, ketmar wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? of course. but D "pure" is not what other world knows as "pure". we love to mess with words. Well, there's the

Re: purity question

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 13:45:07 UTC, Rene Zwanenburg wrote: On Tuesday, 30 May 2017 at 11:34:52 UTC, ketmar wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? of course. but D "pure" is not what other world

Re: purity question

2017-05-30 Thread ag0aep6g via Digitalmars-d-learn
On 05/30/2017 11:12 AM, Rene Zwanenburg wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? D's `pure` mostly means: "does not access mutable state, and does not do input/output". There is never a requirement

Finding the index of the maximum value in an associative array

2017-05-30 Thread Lyle via Digitalmars-d-learn
Hi, I have an associative array of type int[ulong] and I'm trying to get the index of the maximum value, like this: int[ulong] aa = [1UL: 2000, 2UL: 5000, 5UL: 1000]; writeln(aa.maxIndex); // should print 2 Can anyone help me out? Many thanks, Lyle

Re: What is the postfix for min long value?

2017-05-30 Thread Zaydek via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 15:16:13 UTC, tcak wrote: While writing max ulong value, I added the "u" postfix. So compiler accepted it as ulong value (That's my interpretation if correct on compiler's side). writeln( 18_446_744_073_709_551_615u ); But when I try to print out minimum value

Re: Finding the index of the maximum value in an associative array

2017-05-30 Thread cym13 via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 17:57:04 UTC, Lyle wrote: Hi, I have an associative array of type int[ulong] and I'm trying to get the index of the maximum value, like this: int[ulong] aa = [1UL: 2000, 2UL: 5000, 5UL: 1000]; writeln(aa.maxIndex); // should print

Re: What is the postfix for min long value?

2017-05-30 Thread Zaydek via Digitalmars-d-learn
Jonathan, I saw this answered in another post: http://forum.dlang.org/post/gtaublmskqrhnbhoe...@forum.dlang.org I.e., you can do long(-9223372036854775808UL) :) Or long l = -9223372036854775808UL;

Re: purity question

2017-05-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 30, 2017 16:54:13 ag0aep6g via Digitalmars-d-learn wrote: > On 05/30/2017 11:12 AM, Rene Zwanenburg wrote: > > If malloc were marked as pure, wouldn't that mean it must return the > > same pointer every time you call it with the same size? > > D's `pure` mostly means: "does not

Re: Finding the index of the maximum value in an associative array

2017-05-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 30, 2017 at 05:57:04PM +, Lyle via Digitalmars-d-learn wrote: > Hi, > > I have an associative array of type int[ulong] and I'm trying to get > the index of the maximum value, like this: > > int[ulong] aa = [1UL: 2000, > 2UL: 5000, > 5UL: 1000]; >

Re: purity question

2017-05-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 30, 2017 at 11:10:19AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > Yeah, basically, D's pure was originally what is now sometimes called > "strongly pure," which is quite close to functionally pure in that the > same input results in the same output (it still allows

Re: ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 21:42:03 UTC, Daniel Kozak wrote: Compiler do many assumptions (it is sometimes useful). but if compiler find one-to-one correspondence it don't make assumptions, like here? import std.stdio; void f(ushort u) { writeln("ushort"); } void f(ubyte u) {

Re: Finding the index of the maximum value in an associative array

2017-05-30 Thread Lyle via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 18:05:02 UTC, cym13 wrote: On Tuesday, 30 May 2017 at 17:57:04 UTC, Lyle wrote: Hi, I have an associative array of type int[ulong] and I'm trying to get the index of the maximum value, like this: int[ulong] aa = [1UL: 2000, 2UL: 5000,