Strange behavior of cast(int[]) json["my int list"].array

2017-11-15 Thread Enjoys Math via Digitalmars-d-learn
I had it working in an earlier program. Now I have: main.d -- import std.json; import std.file; int main() { JSONValue settings; settings = parseJSON("settings.txt"); auto intList = cast(int[]) settings["int list"].array; writeln(intList); readln(); } for input:

Re: Strange behavior of cast(int[]) json["my int list"].array

2017-11-15 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 19:54:20 UTC, Enjoys Math wrote: I had it working in an earlier program. Now I have: main.d -- import std.json; import std.file; int main() { JSONValue settings; settings = parseJSON("settings.txt"); auto intList = cast(int[]) settings["int

Unable to compile GtkD on windows

2017-11-15 Thread user via Digitalmars-d-learn
I tried compiling GtkD, I get the error message: rdmd Build.d Error: more than 32767 symbols in object file 1. How to work around this? 2. Is D still unfriendly to newbies? I am disappoint :-( Using: DMD 2.077 GtkD 3.7.1 gtk3-runtime_3.22.24-1, 32bit

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread kdevel via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 14:22:51 UTC, Daniel Kozak wrote: And this one https://paste.ofcode.org/KNqxcrmACLZLseB45MvwC I thrash your code with two shell processes ``` while true; do curl 127.0.0.1: -o /dev/null; done ``` running parallel. Using strace -fFeclose on the binary

Re: Treating a slice as an InputRange

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 20:53:39 unleashy via Digitalmars-d-learn wrote: > Hello, > > I'm writing a small parser for a specific binary format. The > format is parsed by way of a sequence of functions, each > deserializing a small portion of the format into a D type such as > int, double,

Re: Unable to compile GtkD on windows

2017-11-15 Thread Mike Wey via Digitalmars-d-learn
On 15-11-17 20:25, user wrote: I tried compiling GtkD, I get the error message: rdmd Build.d Error: more than 32767 symbols in object file 1. How to work around this? 2. Is D still unfriendly to newbies? I am disappoint :-( Using: DMD 2.077 GtkD 3.7.1 gtk3-runtime_3.22.24-1, 32bit It

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread kdevel via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 13:31:46 UTC, Daniel Kozak wrote: This one works ok for me, but I am on linux: https://dpaste.dzfl.pl/f54decee45bc It works, but it does not handle two connects in parallel. STR: 1. start the binary in console 1 2. telnet localhost in console 2 3. telnet

Re: Treating a slice as an InputRange

2017-11-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/15/17 3:53 PM, unleashy wrote: So my question is, is there a way to treat a slice strictly as an InputRange, so that it is mutated no matter what? Or is there another way to do what I'm trying to do? I'd model your functions after the std.conv.parse functions:

Re: Treating a slice as an InputRange

2017-11-15 Thread Ali Çehreli via Digitalmars-d-learn
On 11/15/2017 01:02 PM, Jonathan M Davis wrote: > On Wednesday, November 15, 2017 20:53:39 unleashy via Digitalmars-d-learn >> ubyte[] slice; >> ... >> int a = readInt(slice); >> double b = readDouble(slice); >> >> Ends up failing, because readInt properly reads an int, but the >> slice is not

Re: Treating a slice as an InputRange

2017-11-15 Thread unleashy via Digitalmars-d-learn
Thanks for the insights everyone, it really helped! I actually discovered that it wasn't working because one of the parsing functions used `std.range.take` and, since I was giving it a slice, `take` decided to save the fwdrange instead of mutating it. I realised the `take` call was 100%

Treating a slice as an InputRange

2017-11-15 Thread unleashy via Digitalmars-d-learn
Hello, I'm writing a small parser for a specific binary format. The format is parsed by way of a sequence of functions, each deserializing a small portion of the format into a D type such as int, double, string, etc., operating on a single InputRange. The problem is, if I pass a slice to

Re: ESR on post-C landscape

2017-11-15 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 09:00:38 UTC, Joakim wrote: problems; I want something that helps with apps that are big, distributed, concurrent, and efficient because those are the more important problems people are solving today and in the future."

Re: ESR on post-C landscape

2017-11-15 Thread Paulo Pinto via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 02:05:27 UTC, codephantom wrote: On Tuesday, 14 November 2017 at 16:38:58 UTC, Ola Fosheim Grostad wrote: It [C]is flawed... ESR got that right, not sure how anyone can disagree. Well I 'can' disagree ;-) Is a scalpel flawed because someone tried to use it

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 09:04:50 helxi via Digitalmars-d-learn wrote: > Hi. What function signature should I use for receiving a constant > reference of an r/l value object? Is it auto fn(inout ref const > myClass obj)? > I want to: > 1. Take a constant reference of the object, not copy

Re: ESR on post-C landscape

2017-11-15 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 02:05:27 UTC, codephantom wrote: On Tuesday, 14 November 2017 at 16:38:58 UTC, Ola Fosheim Grostad wrote: It [C]is flawed... ESR got that right, not sure how anyone can disagree. Well I 'can' disagree ;-) Right… :-) Languages are just part of an

Missing return value error not present with template

2017-11-15 Thread Tony via Digitalmars-d-learn
This code: class MyClass { public: int SomeMethod () { } } void main() { } gets a compile error: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int but if I make it a template class: class MyClass(T) { there

Re: Missing return value error not present with template

2017-11-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 08:43:01 UTC, Tony wrote: This code: class MyClass { public: int SomeMethod () { } } void main() { } gets a compile error: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int

Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
Hi. What function signature should I use for receiving a constant reference of an r/l value object? Is it auto fn(inout ref const myClass obj)? I want to: 1. Take a constant reference of the object, not copy them 2. The object itself may be const or non const.

Re: ESR on post-C landscape

2017-11-15 Thread Joakim via Digitalmars-d-learn
On Tuesday, 14 November 2017 at 19:48:07 UTC, Joakim wrote: On Tuesday, 14 November 2017 at 04:31:43 UTC, Laeeth Isharc wrote: He mentions D, a bit dismissively. http://esr.ibiblio.org/?p=7724=1#comment-1912717 Eh, he parrots decade-old anti-D talking points about non-technical,

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread ade90036 via Digitalmars-d-learn
On Tuesday, 14 November 2017 at 21:09:40 UTC, kdevel wrote: On Tuesday, 14 November 2017 at 19:57:54 UTC, ade90036 wrote: while(true) { listeningSet.add(listener); if (Socket.select(listeningSet, null, null, dur!"nsecs"(150)) > 0) { Why do you ever timeout?

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 09:23:53 UTC, Jonathan M Davis wrote: On Wednesday, November 15, 2017 09:04:50 helxi via Digitalmars-d-learn wrote: Hi. What function signature should I use for receiving a constant reference of an r/l value object? Is it auto fn(inout ref const myClass obj)?

Re: ESR on post-C landscape

2017-11-15 Thread codephantom via Digitalmars-d-learn
On Tuesday, 14 November 2017 at 11:55:17 UTC, codephantom wrote: The reason he can dismiss D, so easily, is because of his starting premise that C is flawed. As soon as you begin with that premise, you justify searching for C's replacement, which makes it difficult to envsion something like D.

Re: Missing return value error not present with template

2017-11-15 Thread Tony via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 11:20:24 UTC, Biotronic wrote: Thanks Biotronic! I found this on the html documentation for templates: "The body of the TemplateDeclaration must be syntactically correct even if never instantiated. Semantic analysis is not done until instantiated", and that

Re: ESR on post-C landscape

2017-11-15 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Thursday, 16 November 2017 at 07:12:16 UTC, Ola Fosheim Grostad wrote: But I guess what you are saying is that many people arent good at modelling... I just want to add to this that I believe most people are much better at OO modelling than other modelling strategies (ER, SA, NIAM etc).

Re: ESR on post-C landscape

2017-11-15 Thread rikki cattermole via Digitalmars-d-learn
On 16/11/2017 6:35 AM, Ola Fosheim Grostad wrote: On Thursday, 16 November 2017 at 02:12:10 UTC, codephantom wrote: Perhaps the mistake C++ made, was concluding that 'classes' were the "proper primary focus of program design" (chp1. The Design and Evolution of C++). No, classes is a powerful

Re: ESR on post-C landscape

2017-11-15 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Thursday, 16 November 2017 at 06:51:58 UTC, rikki cattermole wrote: On 16/11/2017 6:35 AM, Ola Fosheim Grostad wrote: Thing is, it is a failure, the way most people use it. You can say that about most things: exceptions, arrays, pointers, memory, structs with public fields... But I guess

Re: ESR on post-C landscape

2017-11-15 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Thursday, 16 November 2017 at 02:12:10 UTC, codephantom wrote: Perhaps the mistake C++ made, was concluding that 'classes' were the "proper primary focus of program design" (chp1. The Design and Evolution of C++). No, classes is a powerful modelling primitive. C++ got that right. C++ is

Re: ESR on post-C landscape

2017-11-15 Thread Bauss via Digitalmars-d-learn
On Thursday, 16 November 2017 at 02:12:10 UTC, codephantom wrote: On Tuesday, 14 November 2017 at 11:55:17 UTC, codephantom wrote: [...] Actually, I got that wrong. Perhaps the mistake C++ made, was concluding that 'classes' were the "proper primary focus of program design" (chp1. The

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 09:34:32 UTC, helxi wrote: On Wednesday, 15 November 2017 at 09:23:53 UTC, Jonathan M Davis wrote: On Wednesday, November 15, 2017 09:04:50 helxi via Digitalmars-d-learn wrote: Hi. What function signature should I use for receiving a constant reference of an

Re: ESR on post-C landscape

2017-11-15 Thread codephantom via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 09:26:49 UTC, Ola Fosheim Grøstad wrote: I don't think Go is much affected by the corporate… Umm "We made the language to help make google more productive and helpful internally" - Rob Pike https://www.youtube.com/watch?v=sln-gJaURzk 2min:55sec To be

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread ade90036 via Digitalmars-d-learn
So thanks for the suggestions, i have fixed HTTP response not postman cal also parse the headers correctly!! happy days. I have removed the duration from the Socket.select but the application seems to process a bunch or requests and then it stalls for several seconds (3/5) and then it

Re: Missing return value error not present with template

2017-11-15 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 08:43:01 UTC, Tony wrote: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int but if I make it a template class: class MyClass(T) { there is no compile error. I don't know why the error

Re: ESR on post-C landscape

2017-11-15 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 10:40:50 UTC, codephantom wrote: On Wednesday, 15 November 2017 at 09:26:49 UTC, Ola Fosheim Grøstad wrote: I don't think Go is much affected by the corporate… Umm "We made the language to help make google more productive and helpful internally" - Rob

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 09:49:56 helxi via Digitalmars-d-learn wrote: > On Wednesday, 15 November 2017 at 09:34:32 UTC, helxi wrote: > > On Wednesday, 15 November 2017 at 09:23:53 UTC, Jonathan M > > > > Davis wrote: > >> On Wednesday, November 15, 2017 09:04:50 helxi via > >> > >>

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread Daniel Kozak via Digitalmars-d-learn
Do not use your own taskPool, just use global taskPool proerty (import std.parallelism: taskPool). You should not set blocking to false. And dont use Thread here. There is no reason to do that. Just move that code into the main Dne 15. 11. 2017 12:15 odp. napsal uživatel "ade90036 via

Re: Best practices for multithread global flags

2017-11-15 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 11:57:25 UTC, Vladimirs Nordholm wrote: Hello people from D-land. To summarise my problem: I have a program in the terminal (Posix) with two threads: one which my main program is run on, and a second one which polls input via `poll(...)` and `read(...)`.

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread Daniel Kozak via Digitalmars-d-learn
And this one https://paste.ofcode.org/KNqxcrmACLZLseB45MvwC Here you can test if threads makes difference when compile with: dmd -O -release -version=SINGLE_THREAD xxx.d it will use only one thread when compile with: dmd -O -release xxx.d it will use thread pool On Wed, Nov 15, 2017 at

How do I use in contract with interface?

2017-11-15 Thread Dr. Assembly via Digitalmars-d-learn
I'm learning to use interface with contracts. In below code, in isn't being "called". Can someone point out why? what am I doing wrong? void main() { C c = new C(); writeln(c.foo(1)); } interface I { int foo(int i) in { assert(i > 2); }

Re: How do I use in contract with interface?

2017-11-15 Thread Dr. Assembly via Digitalmars-d-learn
out(result) {} run fine, if foo() return 0, an exception is throw by assert() but in doesn't work. I don't know what I'm missing. It' my first time using contracts

Re: Best practices for multithread global flags

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 11:57:25 Vladimirs Nordholm via Digitalmars- d-learn wrote: > Hello people from D-land. > > To summarise my problem: I have a program in the terminal (Posix) > with two threads: one which my main program is run on, and a > second one which polls input via

Class instance becoming null after calling bindings to C code???

2017-11-15 Thread Chirs Forest via Digitalmars-d-learn
I'm using the derelict fmod bindings to handle sounds in my application and I'm running into a weird bug... If I put calls to fmod in a function inside a class, upon calling those functions the instance of that class will be null, or otherwise changed. I obviously get an access violation if I

Best practices for multithread global flags

2017-11-15 Thread Vladimirs Nordholm via Digitalmars-d-learn
Hello people from D-land. To summarise my problem: I have a program in the terminal (Posix) with two threads: one which my main program is run on, and a second one which polls input via `poll(...)` and `read(...)`. Let's call main thread T1, and a semi-blocking input-thread T2. Every second

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/15/17 6:46 AM, Jonathan M Davis wrote: On Wednesday, November 15, 2017 09:49:56 helxi via Digitalmars-d-learn wrote: On Wednesday, 15 November 2017 at 09:34:32 UTC, helxi wrote: On Wednesday, 15 November 2017 at 09:23:53 UTC, Jonathan M Davis wrote: On Wednesday, November 15, 2017

Re: Best practices for multithread global flags

2017-11-15 Thread rikki cattermole via Digitalmars-d-learn
On 15/11/2017 11:57 AM, Vladimirs Nordholm wrote: Hello people from D-land. To summarise my problem: I have a program in the terminal (Posix) with two threads: one which my main program is run on, and a second one which polls input via `poll(...)` and `read(...)`. Let's call main thread T1,

Re: Best practices for multithread global flags

2017-11-15 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 11:57:25 UTC, Vladimirs Nordholm wrote: Hello people from D-land. To summarise my problem: I have a program in the terminal (Posix) with two threads: one which my main program is run on, and a second one which polls input via `poll(...)` and `read(...)`.

Re: NIO+Multithreaded TCPSocket listener, very low cpu utilisation

2017-11-15 Thread Daniel Kozak via Digitalmars-d-learn
This one works ok for me, but I am on linux: https://dpaste.dzfl.pl/f54decee45bc On Wed, Nov 15, 2017 at 12:46 PM, Daniel Kozak wrote: > Do not use your own taskPool, just use global taskPool proerty (import > std.parallelism: taskPool). > > You should not set blocking to

Re: Class instance becoming null after calling bindings to C code???

2017-11-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 13:24:02 UTC, Chirs Forest wrote: class Audio { Audio a; writeln(); // 281478 is usually wrong. That's the address of the reference, not of the actual object. You might want `cast(void*) a` instead to print the address of the object itself.

Re: Class instance becoming null after calling bindings to C code???

2017-11-15 Thread Chirs Forest via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 13:30:14 UTC, Adam D. Ruppe wrote: On Wednesday, 15 November 2017 at 13:24:02 UTC, Chirs Forest wrote: class Audio { Audio a; writeln(); // 281478 is usually wrong. That's the address of the reference, not of the actual object. You might want

Re: How do I use in contract with interface?

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 10:33:50 Steven Schveighoffer via Digitalmars-d-learn wrote: > On 11/15/17 10:14 AM, Jonathan M Davis wrote: > > So, it's pointless to put an in contract on an > > > > interface's function unless you're trying to ensure that nothing in > > derived contracts is any

Re: How do I use in contract with interface?

2017-11-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/15/17 9:43 AM, Dr. Assembly wrote: I'm learning to use interface with contracts. In below code, in isn't being "called". Can someone point out why? what am I doing wrong? void main() { C c = new C(); writeln(c.foo(1)); } interface I { int foo(int i)     in { assert(i

Re: How do I use in contract with interface?

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 14:43:33 Dr. Assembly via Digitalmars-d- learn wrote: > I'm learning to use interface with contracts. In below code, in > isn't being "called". Can someone point out why? what am I doing > wrong? > > void main() { > C c = new C(); > writeln(c.foo(1)); > } > >

Re: How do I use in contract with interface?

2017-11-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/15/17 10:14 AM, Jonathan M Davis wrote: So, it's pointless to put an in contract on an interface's function unless you're trying to ensure that nothing in derived contracts is any stricter than that contract, which in practice likely means that it's pointless to put an in contract on an

Re: How do I use in contract with interface?

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 10:14:32 Steven Schveighoffer via Digitalmars-d-learn wrote: > On 11/15/17 9:43 AM, Dr. Assembly wrote: > > I'm learning to use interface with contracts. In below code, in isn't > > being "called". Can someone point out why? what am I doing wrong? > > > > void

Re: How do I use in contract with interface?

2017-11-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/15/17 11:19 AM, Steven Schveighoffer wrote: But what doesn't make a lot of sense is the inability to declare the inheritance of the current in-contract situation. If you have a complex contract, then having to repeat it on every class seems unnecessarily verbose. It's very easy to just

Re: How do I use in contract with interface?

2017-11-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/15/17 10:39 AM, Jonathan M Davis wrote: Well, the rules do make sense when you consider that it can make sense for a function to allow arguments that the base class didn't. The in contract is essentially saying what the function can validly operate on, and there's no reason why a derived

Re: How do I use in contract with interface?

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 11:21:16 Steven Schveighoffer via Digitalmars-d-learn wrote: > On 11/15/17 11:19 AM, Steven Schveighoffer wrote: > > But what doesn't make a lot of sense is the inability to declare the > > inheritance of the current in-contract situation. If you have a complex > >