Re: Deploying Vibe.d applications to OpenShift

2014-07-24 Thread Nikolay via Digitalmars-d-learn
Please let me know how you did it, because I know it's possible with the DIY-cartridge they provide you(atleast it should be). I tried it some time ago. It is possible but: - vibe.d requires a lot of memory for project compilation - it is hard to install additional libraries (it is not

Type deduction on templated constructor.

2014-07-24 Thread francesco cattoglio via Digitalmars-d-learn
So, I have this code (also on http://dpaste.dzfl.pl/3f767b17e83c) This Vector(T) struct is taken from gfm.math.vector. struct Vector(T) { T x, y, z; this(X : T, Y : T, Z : T)(X x_, Y y_, Z z_) { x = x_; y = y_; z = z_; } } void main() {

Re: Type deduction on templated constructor.

2014-07-24 Thread bearophile via Digitalmars-d-learn
francesco cattoglio: should this code compile? I understand that the literal 1 is int therefore it can screw type deduction, but I wonder if the compiler should be smart enough to deduce it correctly. To keep both the compiler and programmers sane, D templates don't perform implicit type

Re: Type deduction on templated constructor.

2014-07-24 Thread francesco cattoglio via Digitalmars-d-learn
On Thursday, 24 July 2014 at 09:38:14 UTC, bearophile wrote: francesco cattoglio: should this code compile? I understand that the literal 1 is int therefore it can screw type deduction, but I wonder if the compiler should be smart enough to deduce it correctly. To keep both the compiler and

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-24 Thread Kagamin via Digitalmars-d-learn
I first try to load the file as utf8 (or some 8kb at the start of it) with encoding exceptions turned on, if I catch an exception, I reload it as ansi, otherwise I assume it's valid utf8.

Re: Deploying Vibe.d applications to OpenShift

2014-07-24 Thread Etienne via Digitalmars-d-learn
On 2014-07-24 3:45 AM, Nikolay wrote: Please let me know how you did it, because I know it's possible with the DIY-cartridge they provide you(atleast it should be). I tried it some time ago. It is possible but: - vibe.d requires a lot of memory for project compilation - it is hard to

Re: Deploying Vibe.d applications to OpenShift

2014-07-24 Thread John Colvin via Digitalmars-d-learn
On Thursday, 24 July 2014 at 02:48:45 UTC, Rutger wrote: On Thursday, 24 July 2014 at 01:47:43 UTC, Rikki Cattermole wrote: On 24/07/2014 1:28 p.m., Rutger wrote: Hello! Really enjoying D so far and have started to toy around with Vibe.d. I was just wondering if someone here has had any

zlibs gzip dosent work with http

2014-07-24 Thread Sean Campbell via Digitalmars-d-learn
I'm trying to add gzip compression to a HTTP server i wrote in D. here is the code that dose the gzip encoding. if ((Info.modGzip) (indexOf(client.getRequestHeaderFieldValue(Accept-Encoding),gzip) != -1)){ writeln(gzip); auto gzip = new Compress(HeaderFormat.gzip);

Segfault games with factorials

2014-07-24 Thread Darren via Digitalmars-d-learn
I have the following code in fac.d (modified from the factorial examples on RosettaCode): #!/usr/bin/rdmd import std.bigint; pure BigInt factorial(BigInt n) { static pure BigInt inner(BigInt n, BigInt acc) { return n == 0 ? acc : inner(n - 1, acc * n); } return inner(n,

Re: zlibs gzip dosent work with http

2014-07-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 24 July 2014 at 13:09:53 UTC, Sean Campbell wrote: I'm trying to add gzip compression to a HTTP server i wrote in D. here is the code that dose the gzip encoding. I know zlib gzip works for http, I used it in my cgi.d if(gzipResponse acceptsGzip isAll) {

Re: Segfault games with factorials

2014-07-24 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 24, 2014 at 01:14:40PM +, Darren via Digitalmars-d-learn wrote: I have the following code in fac.d (modified from the factorial examples on RosettaCode): #!/usr/bin/rdmd import std.bigint; pure BigInt factorial(BigInt n) { static pure BigInt inner(BigInt n, BigInt

Re: Segfault games with factorials

2014-07-24 Thread Darren via Digitalmars-d-learn
On Thursday, 24 July 2014 at 14:39:12 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Thu, Jul 24, 2014 at 01:14:40PM +, Darren via Digitalmars-d-learn wrote: I have the following code in fac.d (modified from the factorial examples on RosettaCode): #!/usr/bin/rdmd import std.bigint;

Re: Segfault games with factorials

2014-07-24 Thread John Colvin via Digitalmars-d-learn
On Thursday, 24 July 2014 at 14:59:16 UTC, Darren wrote: On Thursday, 24 July 2014 at 14:39:12 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Thu, Jul 24, 2014 at 01:14:40PM +, Darren via Digitalmars-d-learn wrote: I have the following code in fac.d (modified from the factorial

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 15:15:36 +, Pavel wrote: Ok, let me start with the sample code: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto parsed = parseJSON(jsonStr); string s =

Re: D JSON (WAT?!)

2014-07-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: string s = parsed[fail].str; Since there is no entry fail in the object, it returns a null JSON_VALUE pointer. Trying to get the string out of it is then seen as a null pointer access and kills the program. Check for null on a key

D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
Ok, let me start with the sample code: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto parsed = parseJSON(jsonStr); string s = parsed[fail].str; writeln(s == ); writeln(s is null); writeln(s); }

Re: D JSON (WAT?!)

2014-07-24 Thread bearophile via Digitalmars-d-learn
Adam D. Ruppe: Check for null on a key before trying to get a value out. Is something like the get() function usable here? Bye, bearophile

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:22:46 UTC, Adam D. Ruppe wrote: On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: string s = parsed[fail].str; Since there is no entry fail in the object, it returns a null JSON_VALUE pointer. Trying to get the string out of it is then seen as a null

Re: D JSON (WAT?!)

2014-07-24 Thread Daniel Gibson via Digitalmars-d-learn
Am 24.07.2014 17:29, schrieb Pavel: On Thursday, 24 July 2014 at 15:22:46 UTC, Adam D. Ruppe wrote: On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: string s = parsed[fail].str; Since there is no entry fail in the object, it returns a null JSON_VALUE pointer. Trying to get the string

Re: D JSON (WAT?!)

2014-07-24 Thread Ali Çehreli via Digitalmars-d-learn
On 07/24/2014 08:29 AM, Pavel wrote: writeln(parsed[fail] == null); Now compiler complains: Error: incompatible types for ((parsed.opIndex(fail)) == (null)): 'JSONValue' and 'typeof(null)' WAT?! Comparing against null should be done with the 'is' operator, not the == operator: if

Re: D JSON (WAT?!)

2014-07-24 Thread John Colvin via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: Ok, let me start with the sample code: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto parsed = parseJSON(jsonStr); string s = parsed[fail].str;

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:31:30 UTC, Daniel Gibson wrote: Am 24.07.2014 17:29, schrieb Pavel: On Thursday, 24 July 2014 at 15:22:46 UTC, Adam D. Ruppe wrote: On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: string s = parsed[fail].str; Since there is no entry fail in the

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:20:58 UTC, Justin Whear wrote: On Thu, 24 Jul 2014 15:15:36 +, Pavel wrote: Ok, let me start with the sample code: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto

Re: Segfault games with factorials

2014-07-24 Thread safety0ff via Digitalmars-d-learn
On Thursday, 24 July 2014 at 14:59:16 UTC, Darren wrote: It does seem that's the case. Which is odd, as I thought that DMD and LDC did TCO. Not in this case obviously. DMD doesn't do it with the :? operator: https://issues.dlang.org/show_bug.cgi?id=3713

Re: D JSON (WAT?!)

2014-07-24 Thread John Colvin via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: Ok, let me start with the sample code: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:34:22 UTC, Ali Çehreli wrote: On 07/24/2014 08:29 AM, Pavel wrote: writeln(parsed[fail] == null); Now compiler complains: Error: incompatible types for ((parsed.opIndex(fail)) == (null)): 'JSONValue' and 'typeof(null)' WAT?! Comparing against null should

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: Ok, let me start with the sample code: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:42:58 UTC, Pavel wrote: On Thursday, 24 July 2014 at 15:38:06 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: Ok, let me start with the sample code: import std.stdio;

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:38:06 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: Ok, let me start with the sample code: import std.stdio; import std.json; void main() { scope(failure)

Re: D JSON (WAT?!)

2014-07-24 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:42:58 UTC, Pavel wrote: On Thursday, 24 July 2014 at 15:38:06 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:15:37 UTC, Pavel wrote: Ok, let me start with the sample code: import std.stdio;

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:48:32 UTC, Edwin van Leeuwen wrote: On Thursday, 24 July 2014 at 15:42:58 UTC, Pavel wrote: On Thursday, 24 July 2014 at 15:38:06 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:15:37 UTC,

Re: D JSON (WAT?!)

2014-07-24 Thread Daniel Gibson via Digitalmars-d-learn
Am 24.07.2014 17:54, schrieb Pavel: Guess what, here's a new snippet: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto parsed = parseJSON(jsonStr).object; writeln(fail in parsed); } Output is: null

Re: D JSON (WAT?!)

2014-07-24 Thread bearophile via Digitalmars-d-learn
Pavel: writeln(cast(bool)(fail in parsed)); Produces false... but why on earth boolean expression would output null? In D if you perform an associative array in, the return isn't a boolean but a pointer. It's zero if the item is not present. And it's a valid pointer to the value if the

Re: D JSON (WAT?!)

2014-07-24 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 24, 2014 at 03:54:20PM +, Pavel via Digitalmars-d-learn wrote: [...] Guess what, here's a new snippet: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto parsed =

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:59:52 UTC, Daniel Gibson wrote: Am 24.07.2014 17:54, schrieb Pavel: Guess what, here's a new snippet: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto parsed =

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 15:54:20 +, Pavel wrote: On Thursday, 24 July 2014 at 15:48:32 UTC, Edwin van Leeuwen wrote: On Thursday, 24 July 2014 at 15:42:58 UTC, Pavel wrote: On Thursday, 24 July 2014 at 15:38:06 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin

Re: D JSON (WAT?!)

2014-07-24 Thread John Colvin via Digitalmars-d-learn
On Thursday, 24 July 2014 at 15:54:21 UTC, Pavel wrote: On Thursday, 24 July 2014 at 15:48:32 UTC, Edwin van Leeuwen wrote: On Thursday, 24 July 2014 at 15:42:58 UTC, Pavel wrote: On Thursday, 24 July 2014 at 15:38:06 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:32:29 UTC, John

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real problem, which is JSON wrapper class. Is it needed? Wouldn't it be better to get AA from parseJSON? The following are valid JSON: auto json1 =

Passing an array by reference?

2014-07-24 Thread Rishub Nagpal via Digitalmars-d-learn
1 class Test 2 { 3 int[][] array; 4 this(ref int[][] d) 5 { 6 array = d; 7 } 8 9 } 10 11 void main() 12 { 13 Test t = new Test([[1,1],[1,1]]); //does not compile 14 } 15 what is the best way to pass a literal ([[1,2],[3,4]]) by reference?

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 16:02:12 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Thu, Jul 24, 2014 at 03:54:20PM +, Pavel via Digitalmars-d-learn wrote: [...] Guess what, here's a new snippet: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!);

Re: D JSON (WAT?!)

2014-07-24 Thread Pavel via Digitalmars-d-learn
On Thursday, 24 July 2014 at 16:09:25 UTC, Justin Whear wrote: On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real problem, which is JSON wrapper class. Is it needed? Wouldn't it be better to get AA from

Re: Passing an array by reference?

2014-07-24 Thread John Colvin via Digitalmars-d-learn
On Thursday, 24 July 2014 at 16:06:00 UTC, Rishub Nagpal wrote: 1 class Test 2 { 3 int[][] array; 4 this(ref int[][] d) 5 { 6 array = d; 7 } 8 9 } 10 11 void main() 12 { 13 Test t = new Test([[1,1],[1,1]]); //does not compile 14 } 15 what

Re: D JSON (WAT?!)

2014-07-24 Thread Ary Borenszweig via Digitalmars-d-learn
On 7/24/14, 1:09 PM, Justin Whear wrote: On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real problem, which is JSON wrapper class. Is it needed? Wouldn't it be better to get AA from parseJSON? The

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 13:49:27 -0300, Ary Borenszweig wrote: Nope, a JSON can only be an array or an object (hash). Ary, can you point out the place in the spec where this is specified? Not to be pedantic, but the spec only seems to define a JSON value, not a JSON document.

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 16:14:15 +, Pavel wrote: On Thursday, 24 July 2014 at 16:09:25 UTC, Justin Whear wrote: On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real problem, which is JSON wrapper class. Is

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 17:05:17 +, Gary Willoughby wrote: I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10); That got

How to copy an object to separate allocated memory?

2014-07-24 Thread Gary Willoughby via Digitalmars-d-learn
I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10); That got me thinking, how would i actually 'fill' this memory with

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Daniel Gibson via Digitalmars-d-learn
Am 24.07.2014 19:05, schrieb Gary Willoughby: I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10); That got me thinking, how

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread John Colvin via Digitalmars-d-learn
On Thursday, 24 July 2014 at 17:05:18 UTC, Gary Willoughby wrote: I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10);

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 17:07:29 +, Justin Whear wrote: On Thu, 24 Jul 2014 17:05:17 +, Gary Willoughby wrote: I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer =

Mocking serial device

2014-07-24 Thread Alfredo Palhares via Digitalmars-d-learn
Hello, I am writing an application that connects to a serial device in /dev/ttyUSB0 and trows some binary data back and forth. How can i mock and run some unit testing without having to connect to the device every time? -- Regards, Alfredo Palhares

dual with statement

2014-07-24 Thread Jay Norwood via Digitalmars-d-learn
I was playing around with use of the dual WITH statement. I like the idea, since it makes the code within the with cleaner. Also, I got the impression from one of the conference presentations ... maybe the one on the ARM debug ... that there are some additional optimizations available that

Re: Mocking serial device

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 17:15:02 +, Alfredo Palhares wrote: Hello, I am writing an application that connects to a serial device in /dev/ttyUSB0 and trows some binary data back and forth. How can i mock and run some unit testing without having to connect to the device every time? How

Re: Mocking serial device

2014-07-24 Thread Alfredo Palhares via Digitalmars-d-learn
Hello, How about capturing some data from the device and writing it to a file? When you want to test, open the test data file instead of the device file. That would not work since the data is two way, for the device to even trow data at me I need to send some values to it. -- Regards,

Appender.put return value

2014-07-24 Thread JR via Digitalmars-d-learn
Is there a big reason why Appender.put doesn't return this? http://dpaste.dzfl.pl/bb840e3e349e It would allow for convenient chaining. :

Re: Appender.put return value

2014-07-24 Thread Temtaime via Digitalmars-d-learn
Offtop It's better to return this and have return type ref auto i think.

Re: D JSON (WAT?!)

2014-07-24 Thread Ary Borenszweig via Digitalmars-d-learn
On 7/24/14, 1:58 PM, Justin Whear wrote: On Thu, 24 Jul 2014 13:49:27 -0300, Ary Borenszweig wrote: Nope, a JSON can only be an array or an object (hash). Ary, can you point out the place in the spec where this is specified? Not to be pedantic, but the spec only seems to define a JSON value,

Create a general array

2014-07-24 Thread Robert Rimoczi via Digitalmars-d-learn
Hi! Can I somehow make a general array where I can store everykind of object? doubles, ints, float, class objects? Or is there any method for it?