Re: Problem overloading operator for a struct with an immutable member

2015-03-25 Thread ketmar via Digitalmars-d-learn
On Thu, 26 Mar 2015 05:44:13 +, Jean pierre wrote: > auto i = s++; // OUCH, but we expect S.i... but why one expecting `i` here? there IS `opUnary` overload, and `++` corretly transformed to prefix form. there is simply NO postfix form in semantically analyzed code, *all* postfix incremen

Re: Problem overloading operator for a struct with an immutable member

2015-03-25 Thread Jean pierre via Digitalmars-d-learn
On Thursday, 26 March 2015 at 04:57:55 UTC, ketmar wrote: On Tue, 24 Mar 2015 16:49:01 +, Nicolas Sicard wrote: I don't know if this is a bug or expected behaviour. The struct is mutable, assignable and pre-increment operator works. But post-increment doesn't compile because of the immuta

Re: Looking for a little help with the win32 headers

2015-03-25 Thread Jean pierre via Digitalmars-d-learn
On Thursday, 26 March 2015 at 04:52:23 UTC, Belly wrote: Hello, just installed D today. I have this code: import std.stdio; import win32.windef; import win32.winbase; void main() { LPSTR lpBuffer; PDWORD lpnSize; int result = GetComputerNameA(lpBuffer, lpnSize); writeln(result)

Re: Looking for a little help with the win32 headers

2015-03-25 Thread Rikki Cattermole via Digitalmars-d-learn
On 26/03/2015 5:52 p.m., Belly wrote: Hello, just installed D today. I have this code: import std.stdio; import win32.windef; import win32.winbase; void main() { LPSTR lpBuffer; PDWORD lpnSize; int result = GetComputerNameA(lpBuffer, lpnSize); writeln(result); } It passes

Re: Problem overloading operator for a struct with an immutable member

2015-03-25 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Mar 2015 16:49:01 +, Nicolas Sicard wrote: > I don't know if this is a bug or expected behaviour. The struct is > mutable, assignable and pre-increment operator works. But post-increment > doesn't compile because of the immutable member. > > -- > struct S { > int i; > imm

Re: Problem overloading operator for a struct with an immutable member

2015-03-25 Thread ketmar via Digitalmars-d-learn
On Tue, 24 Mar 2015 16:49:01 +, Nicolas Sicard wrote: > I don't know if this is a bug or expected behaviour. The struct is > mutable, assignable and pre-increment operator works. But post-increment > doesn't compile because of the immutable member. > > -- > struct S { > int i; > imm

Looking for a little help with the win32 headers

2015-03-25 Thread Belly via Digitalmars-d-learn
Hello, just installed D today. I have this code: import std.stdio; import win32.windef; import win32.winbase; void main() { LPSTR lpBuffer; PDWORD lpnSize; int result = GetComputerNameA(lpBuffer, lpnSize); writeln(result); } It passes zeroes to the API, I'm stuck and can't find

Re: problems with std.bitmanip.append

2015-03-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/25/15 1:29 PM, Hugo wrote: On Wednesday, 25 March 2015 at 17:09:05 UTC, John Colvin wrote: As per the signature in the docs: void append(T, Endian endianness = Endian.bigEndian, R)(R range, T value) The endianness is the second template argument. What you need to write is buffer.append!(

Re: Garbage collector collects live objects

2015-03-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/25/15 9:51 AM, Ali Çehreli wrote: On 12/09/2014 08:53 AM, Steven Schveighoffer wrote: > On 12/9/14 11:17 AM, ketmar via Digitalmars-d-learn wrote: >> that file can be already finalized. please remember that `~this()` is >> more a finalizer than destructor, and it's called on *dead* obje

Re: using vibe.d to parse json

2015-03-25 Thread Laeeth Isharc via Digitalmars-d-learn
On Thursday, 26 March 2015 at 01:04:06 UTC, Jakob Ovrum wrote: On Thursday, 26 March 2015 at 00:41:50 UTC, Laeeth Isharc wrote: Yeah, it is not very intuitive. But it works. Thanks. Next question - how can I correctly deal with inconsiderately chosen JSON field names like 'private' (which co

Re: using vibe.d to parse json

2015-03-25 Thread Jakob Ovrum via Digitalmars-d-learn
On Thursday, 26 March 2015 at 00:41:50 UTC, Laeeth Isharc wrote: Yeah, it is not very intuitive. But it works. Thanks. Next question - how can I correctly deal with inconsiderately chosen JSON field names like 'private' (which conflict in a struct declaration with D language keywords). A ha

Re: using vibe.d to parse json

2015-03-25 Thread Dicebot via Digitalmars-d-learn
On Thursday, 26 March 2015 at 00:41:50 UTC, Laeeth Isharc wrote: Yeah, it is not very intuitive. But it works. Thanks. Next question - how can I correctly deal with inconsiderately chosen JSON field names like 'private' (which conflict in a struct declaration with D language keywords). A ha

Re: using vibe.d to parse json

2015-03-25 Thread Laeeth Isharc via Digitalmars-d-learn
Yeah, it is not very intuitive. But it works. Thanks. Next question - how can I correctly deal with inconsiderately chosen JSON field names like 'private' (which conflict in a struct declaration with D language keywords). A hack is to do a search and replace on the JSON before presenting it

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Ivan Kazmenko: arr.map !(to !(string)) .join (" ") .writeln; I suggest to not put a space before the bang (!), because it's confusing for me. Also, "arr.map !(to !(string))" is better written "arr.map!text". But even better is to use the range formatting of writefln, a

Re: Keep Track of the Best N Nodes in a Graph Traversal Algorithm

2015-03-25 Thread bearophile via Digitalmars-d-learn
Nordlöw: Ahh, a Binary Heap perfectly matches my needs. https://en.wikipedia.org/wiki/Binary_heap http://dlang.org/phobos/std_container_binaryheap.html But isn't topNCopy using a heap? Bye, bearophile

Re: Keep Track of the Best N Nodes in a Graph Traversal Algorithm

2015-03-25 Thread Nordlöw
On Wednesday, 25 March 2015 at 17:49:49 UTC, Tobias Pankrath wrote: What's wrong with binary heaps? Ahh, a Binary Heap perfectly matches my needs. https://en.wikipedia.org/wiki/Binary_heap http://dlang.org/phobos/std_container_binaryheap.html Thx

Re: C# to D

2015-03-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:09:53 UTC, bearophile wrote: This is still not very efficient (perhaps the last sorting has to be stable): void main() { import std.stdio, std.algorithm, std.typecons, std.array; [7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1, 2, 2, 8, 5, 8, 8]

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:17:57 UTC, bearophile wrote: Ivan Kazmenko: (1) For me, the name of the function is obscure. Something like sortBy would be a lot easier to find than schwartzSort. I've asked to change the name of that function for years. But Andrei Alexandrescu is a adaman

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:09:53 UTC, bearophile wrote: Dennis Ritchie: A more effective solution for C ++: #include #include #include int main() { using namespace ranges; auto rng = istream( std::cin ) | to_vector | action::sort | view::group_by( st

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:02:20 UTC, Ivan Kazmenko wrote: Will file an issue soon. Here it is: https://issues.dlang.org/show_bug.cgi?id=14340 And another one, a 2.067 regression: https://issues.dlang.org/show_bug.cgi?id=14341

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Ivan Kazmenko: (1) For me, the name of the function is obscure. Something like sortBy would be a lot easier to find than schwartzSort. I've asked to change the name of that function for years. But Andrei Alexandrescu is a adamantly against changing that pet name he has chosen. This is irrat

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Dennis Ritchie: A more effective solution for C ++: #include #include #include int main() { using namespace ranges; auto rng = istream( std::cin ) | to_vector | action::sort | view::group_by( std::equal_to() ) | copy | action::stab

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 19:32:43 UTC, Dennis Ritchie wrote: On Wednesday, 25 March 2015 at 19:01:43 UTC, bearophile wrote: One solution: Thanks. On Wednesday, 25 March 2015 at 19:03:27 UTC, bearophile wrote: But calling "count" for each item is not efficient (in both C# and D). If you

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:02:20 UTC, Ivan Kazmenko wrote: (2) The documentation says it is more efficient than the first version in the number of comparisons (verbose lambda with plain sort) [1], but I don't get how it is possible: unless we know than (not pred1(a,b)) and (not !pred1(a,

Re: C# to D

2015-03-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 19:01:43 UTC, bearophile wrote: One solution: Thanks. On Wednesday, 25 March 2015 at 19:03:27 UTC, bearophile wrote: But calling "count" for each item is not efficient (in both C# and D). If your array is largish, then you need a more efficient solution. A mo

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Ali Çehreli: Do you know the story about groupBy? It's a long messy story. Look for it with another name, like chunkBy or something like that. Bye, bearophile

Re: C# to D

2015-03-25 Thread Ali Çehreli via Digitalmars-d-learn
On 03/25/2015 12:01 PM, bearophile wrote: bearophile Do you know the story about groupBy? I see it in the documentation but my git head does not have it: http://dlang.org/phobos/std_algorithm_iteration.html#.groupBy Ali

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
.schwartzSort!(x => tuple(-arr.count!(y => y == x), x)) But calling "count" for each item is not efficient (in both C# and D). If your array is largish, then you need a more efficient solution. Bye, bearophile

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Dennis Ritchie: int[] arr = { 7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1, 2, 2, 8, 5, 8, 8 }; Console.WriteLine(string.Join(" ", arr.OrderByDescending(x => arr.Count(y => y == x)).ThenBy(x => x))); // prints 1 1 1 1 1 3 3 3 3 3 5 5 5 5 8 8 8 2 2 7 7 0 One solutio

C# to D

2015-03-25 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Can you please tell how to rewrite this code to D? using System; using System.Linq; class Sort { static void Main() { int[] arr = { 7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1, 2, 2, 8, 5, 8, 8 }; Console.WriteLine(string.Join(" ", arr.OrderByDescending(x => arr.C

Re: How to properly Thread.sleep?

2015-03-25 Thread Israel via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 17:25:50 UTC, Sad panda wrote: Thread.sleep(200.msecs); Thread.sleep(12.seconds); Thread.sleep(1.minutes); There we go, thank you so much.

Re: Keep Track of the Best N Nodes in a Graph Traversal Algorithm

2015-03-25 Thread Tobias Pankrath via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 14:40:28 UTC, Per Nordlöw wrote: On Wednesday, 25 March 2015 at 13:55:29 UTC, bearophile wrote: Nordlöw: I have graph traversal algorithm that needs to keep track of the N "best" node visit. std.algorithm.topNCopy? Bye, bearophile Notice that, ideally, I wou

Re: How to properly Thread.sleep?

2015-03-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 17:23:40 UTC, Israel wrote: What is the proper way of adding sleep time to a program? The documentation examples are exactly how you can do it: Thread.sleep( dur!("msecs")( 50 ) ); // sleep for 50 milliseconds Thread.sleep( dur!("seconds")( 5 ) ); // sleep for 5

Re: How to properly Thread.sleep?

2015-03-25 Thread Ali Çehreli via Digitalmars-d-learn
On 03/25/2015 10:23 AM, Israel wrote: > Ive tried using google but no matter what code i find it either doesnt > work, compiler gives me errors or maybe the code is deprecated. > > What is the proper way of adding sleep time to a program? > Ive tried.. > > import std.stdio; > import core.thread;

Re: problems with std.bitmanip.append

2015-03-25 Thread Hugo via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 17:09:05 UTC, John Colvin wrote: As per the signature in the docs: void append(T, Endian endianness = Endian.bigEndian, R)(R range, T value) The endianness is the second template argument. What you need to write is buffer.append!(uint, Endian.littleEndian)(c

Re: How to properly Thread.sleep?

2015-03-25 Thread Sad panda via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 17:23:40 UTC, Israel wrote: Ive tried using google but no matter what code i find it either doesnt work, compiler gives me errors or maybe the code is deprecated. What is the proper way of adding sleep time to a program? Ive tried.. import std.stdio; import core

How to properly Thread.sleep?

2015-03-25 Thread Israel via Digitalmars-d-learn
Ive tried using google but no matter what code i find it either doesnt work, compiler gives me errors or maybe the code is deprecated. What is the proper way of adding sleep time to a program? Ive tried.. import std.stdio; import core.thread; void main() { writeln("Sleep.."); sleep(

Re: OPTLINK Error 45 "Too Much DEBUG Data for Old CodeView format"

2015-03-25 Thread Koi via Digitalmars-d-learn
On Monday, 23 March 2015 at 13:29:15 UTC, wobbles wrote: Maybe this should be distributed in the DMD installer? i don't know :)

Re: problems with std.bitmanip.append

2015-03-25 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 15:44:50 UTC, Hugo wrote: Hi, I need to append an uint as an array of ubytes (in little endian) to an existing array of ubytes. I tried to compile this code (with dmd 2.066.1 under Windows 7 x86-64): void main() { ubyte[] buffer = [0x1f, 0x8b, 0x08, 0x00];

Re: Is there websocket client implementation for D

2015-03-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 07:12:56 UTC, thedeemon wrote: It's for server side, but probably contains stuff you need for client too. Yeah, I've been meaning to write a client for a while but haven't gotten around to it yet. What you do is make a HTTP request with a particular header, and

problems with std.bitmanip.append

2015-03-25 Thread Hugo via Digitalmars-d-learn
Hi, I need to append an uint as an array of ubytes (in little endian) to an existing array of ubytes. I tried to compile this code (with dmd 2.066.1 under Windows 7 x86-64): void main() { ubyte[] buffer = [0x1f, 0x8b, 0x08, 0x00]; import std.system; import std.datetime : Clock, stdTi

Re: Keep Track of the Best N Nodes in a Graph Traversal Algorithm

2015-03-25 Thread via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 13:55:29 UTC, bearophile wrote: Nordlöw: I have graph traversal algorithm that needs to keep track of the N "best" node visit. std.algorithm.topNCopy? Bye, bearophile Notice that, ideally, I would like my list of top-nodes to have a fixed size during the who

Re: Keep Track of the Best N Nodes in a Graph Traversal Algorithm

2015-03-25 Thread via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 13:55:29 UTC, bearophile wrote: Nordlöw: I have graph traversal algorithm that needs to keep track of the N "best" node visit. std.algorithm.topNCopy? Bye, bearophile Could you please elaborate a bit how you mean this should be used. Notice that the number o

Re: Keep Track of the Best N Nodes in a Graph Traversal Algorithm

2015-03-25 Thread bearophile via Digitalmars-d-learn
Nordlöw: I have graph traversal algorithm that needs to keep track of the N "best" node visit. std.algorithm.topNCopy? Bye, bearophile

Re: Garbage collector collects live objects

2015-03-25 Thread Ali Çehreli via Digitalmars-d-learn
On 12/09/2014 08:53 AM, Steven Schveighoffer wrote: > On 12/9/14 11:17 AM, ketmar via Digitalmars-d-learn wrote: >> that file can be already finalized. please remember that `~this()` is >> more a finalizer than destructor, and it's called on *dead* object. Agreed: D has a terminology issue here

Keep Track of the Best N Nodes in a Graph Traversal Algorithm

2015-03-25 Thread via Digitalmars-d-learn
I have graph traversal algorithm that needs to keep track of the N "best" node visit. Every time a visit a new node I get its goodness along with a ref to it. I then want to compare it to every currently best node in this list and replace it with the worst one if its better than the worst. How

Re: D's type classes pattern ?

2015-03-25 Thread matovitch via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 08:55:14 UTC, bearophile wrote: matovitch: I am curious to know how isInputRange is implemented since I wanted to do kind of the same but I am afraid it's full of (ugly) traits and template trickeries where haskell type classes are quite neat and essentially a d

Re: D's type classes pattern ?

2015-03-25 Thread bearophile via Digitalmars-d-learn
matovitch: I am curious to know how isInputRange is implemented since I wanted to do kind of the same but I am afraid it's full of (ugly) traits and template trickeries where haskell type classes are quite neat and essentially a declaration of an interface. Take a look at the sources and lea

Re: D's type classes pattern ?

2015-03-25 Thread matovitch via Digitalmars-d-learn
Thanks for the precisions on template constraint and template specialization...Indeed wath I want to do look like isInputRange constraint. Haskell have something like : //(Pseudo D-Haskell) void foo(InputRange R)(R r); //D equivalent void foo(R)(R r) if (isInputRange(R)); Except they call the

Re: Is there websocket client implementation for D

2015-03-25 Thread thedeemon via Digitalmars-d-learn
On Tuesday, 24 March 2015 at 17:55:38 UTC, Ilya Korobitsyn wrote: Hello! Is there any websocket client implementation in D? There's some WebSocket stuff here: https://github.com/adamdruppe/arsd/blob/master/cgi.d It's for server side, but probably contains stuff you need for client too.