Re: Managing memory usage at Compile Time with DMD

2015-04-09 Thread Rikki Cattermole via Digitalmars-d-learn
On 9/04/2015 9:49 p.m., wobbles wrote: So, I'm writing a poker AI bot. The idea was to generate a lookup table of all the poker hands using CTFE so runtime can be as quick as possible (as the bot has a very small amount of time to act). There are a LOT of calculations though, many millions of

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Adam D. Ruppe via Digitalmars-d-learn
Don't use string == null, it is true for empty strings since null and an empty string are almost interchangable. You can try if(string is null) - is instead of ==. Though usually in D, I just if(string.length == 0) and treat empty and null the same way.

Re: return the other functions of the void main()

2015-04-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:07:05 UTC, Rikki Cattermole wrote: Sure when: import std.traits : ReturnType; import std.stdio : writeln; static assert(is(ReturnType!writeln == int)); Thanks. On Thursday, 9 April 2015 at 11:09:43 UTC, John Colvin wrote: Yes, because writeln returns nothing,

Re: return the other functions of the void main()

2015-04-09 Thread John Colvin via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:07:05 UTC, Rikki Cattermole wrote: On 9/04/2015 11:03 p.m., Dennis Ritchie wrote: Hi, Is it allowed in D similar designs? void main() { import std.stdio; return writeln(Hello, world!); } Sure when: import std.traits : ReturnType; import std.stdio :

Managing memory usage at Compile Time with DMD

2015-04-09 Thread wobbles via Digitalmars-d-learn
So, I'm writing a poker AI bot. The idea was to generate a lookup table of all the poker hands using CTFE so runtime can be as quick as possible (as the bot has a very small amount of time to act). There are a LOT of calculations though, many millions of combinations. During complation,

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:45:31 UTC, tcak wrote: I have written a function as follows: public bool setCookie( string name, string value, long maxAgeInSeconds = long.min, string expiresOnGMTDate=null, string path=null, string domain=null,

Re: return the other functions of the void main()

2015-04-09 Thread Rikki Cattermole via Digitalmars-d-learn
On 9/04/2015 11:22 p.m., John Colvin wrote: On Thursday, 9 April 2015 at 11:07:05 UTC, Rikki Cattermole wrote: On 9/04/2015 11:03 p.m., Dennis Ritchie wrote: Hi, Is it allowed in D similar designs? void main() { import std.stdio; return writeln(Hello, world!); } Sure when: import

Re: Escape a string ?

2015-04-09 Thread Temtaime via Digitalmars-d-learn
Sorry, i meant it gives b == fooo\\nbar I'm writing an interpreter and it should dump original string from memory. Also i wonder if there's a function to convert aaa\\nbb to aaa\nbb (i.e. to unescape)

Re: function shadowed

2015-04-09 Thread ddos via Digitalmars-d-learn
On Thursday, 9 April 2015 at 05:34:09 UTC, anonymous wrote: On Wednesday, 8 April 2015 at 22:53:39 UTC, ddos wrote: why not just make it callable without the alias? It's to prevent hijacking: http://dlang.org/hijack.html thx for the article!

Re: Managing memory usage at Compile Time with DMD

2015-04-09 Thread wobbles via Digitalmars-d-learn
On Thursday, 9 April 2015 at 10:04:09 UTC, John Colvin wrote: On Thursday, 9 April 2015 at 09:49:39 UTC, wobbles wrote: Another possibilty I was looking at was to write a tool that will spit out all combinations at runtime, and then import these back into the bot at compile time to build a

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 14:49:24 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:42:33 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:30:07 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:25:56 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:16:00

Re: Managing memory usage at Compile Time with DMD

2015-04-09 Thread John Colvin via Digitalmars-d-learn
On Thursday, 9 April 2015 at 09:49:39 UTC, wobbles wrote: Another possibilty I was looking at was to write a tool that will spit out all combinations at runtime, and then import these back into the bot at compile time to build a lookup table that way. Thanks! This is definitely a better

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 14:42:33 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:30:07 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:25:56 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:16:00 UTC, tcak wrote: By the way, I am using DMD64 D Compiler v2.067.0

Re: Escape a string ?

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 13:09:57 UTC, Temtaime wrote: Hi ! I wonder how to escape a string in phobos ? For example auto a = [ fooo\nbar ]; auto b = format(%(%s%), a); gives b: fooo\nbar Is there any other function to escape string? I'm looking for something that doesn't require to make

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 09 Apr 2015 11:45:30 + tcak via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I have written a function as follows: public bool setCookie( string name, string value, long maxAgeInSeconds = long.min, string expiresOnGMTDate=null,

Re: return the other functions of the void main()

2015-04-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 9 April 2015 at 17:38:42 UTC, Dennis Ritchie wrote: I think it has something to do with Vindovs :) *Windows

Re: return the other functions of the void main()

2015-04-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 9 April 2015 at 17:08:44 UTC, Dennis Ritchie wrote: Operates a code normally, but still gives the error: http://ideone.com/kDHMk5 I think it has something to do with Vindovs :) - http://dpaste.dzfl.pl/4c5bb9dd0ffa

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 09 Apr 2015 11:04:47 -0400 Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Note that the bad behavior (which was just fixed BTW) is if(somearr), which used to mean if(somearr.ptr), and now it's a compiler error. -Steve Yeah, because of this I

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 09 Apr 2015 11:04:47 -0400 Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Note that the bad behavior (which was just fixed BTW) is if(somearr), which used to mean if(somearr.ptr), and now it's a compiler error. -Steve Yeah, because of this I

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 14:30:07 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:25:56 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:16:00 UTC, tcak wrote: By the way, I am using DMD64 D Compiler v2.067.0 on Ubuntu 14.04. I have Archlinux DMD64 D Compiler v2.067.0

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 13:32:38 UTC, Adam D. Ruppe wrote: Don't use string == null, it is true for empty strings since null and an empty string are almost interchangable. You can try if(string is null) - is instead of ==. Though usually in D, I just if(string.length == 0) and treat

Re: Generating all combinations of length X in an array

2015-04-09 Thread bearophile via Digitalmars-d-learn
wobbles: Have just tested, it is! But with the current D front-end it's not a good idea to generate too many combinations at compile-time. Efficient code doesn't save you from bad usages. Bye, bearophile

Re: Managing memory usage at Compile Time with DMD

2015-04-09 Thread Vladimir Panteleev via Digitalmars-d-learn
On Thursday, 9 April 2015 at 09:49:39 UTC, wobbles wrote: So, I'm writing a poker AI bot. The idea was to generate a lookup table of all the poker hands using CTFE so runtime can be as quick as possible (as the bot has a very small amount of time to act). There are a LOT of calculations

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/9/15 9:32 AM, Adam D. Ruppe wrote: Don't use string == null, it is true for empty strings since null and an empty string are almost interchangable. I think this is not good advice. Comparing string to null is perfectly fine with ==. It's fine *because* null and empty strings are the same

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 14:25:56 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:16:00 UTC, tcak wrote: By the way, I am using DMD64 D Compiler v2.067.0 on Ubuntu 14.04. I have Archlinux DMD64 D Compiler v2.067.0 and it works OK for me. WOW rdmd app.d(without params): Name:

Re: return the other functions of the void main()

2015-04-09 Thread via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:09:43 UTC, John Colvin wrote: On Thursday, 9 April 2015 at 11:04:00 UTC, Dennis Ritchie wrote: Hi, Is it allowed in D similar designs? void main() { import std.stdio; return writeln(Hello, world!); } Yes, because writeln returns nothing, but

Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
I have written a function as follows: public bool setCookie( string name, string value, long maxAgeInSeconds = long.min, string expiresOnGMTDate=null, string path=null, string domain=null, bool secure=false ) shared{ // if headers

Re: return the other functions of the void main()

2015-04-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:04:00 UTC, Dennis Ritchie wrote: Hi, Is it allowed in D similar designs? void main() { import std.stdio; return writeln(Hello, world!); } It seems that you can not do so because writeln() something back, which leads to RUNTIME_ERROR in DMD

Re: return the other functions of the void main()

2015-04-09 Thread Jack Applegame via Digitalmars-d-learn
I quite often have to write similar designs: - import std.stdio; void main() { auto a = [ 1, 2, 3, 4, 5 ]; foreach (e; a) { if (e == 4) { writeln(Yes); return; } }

Re: return the other functions of the void main()

2015-04-09 Thread John Colvin via Digitalmars-d-learn
On Thursday, 9 April 2015 at 16:02:01 UTC, Dennis Ritchie wrote: On Thursday, 9 April 2015 at 11:04:00 UTC, Dennis Ritchie wrote: Hi, Is it allowed in D similar designs? void main() { import std.stdio; return writeln(Hello, world!); } It seems that you can not do so because

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 9 April 2015 at 15:04:47 UTC, Steven Schveighoffer wrote: You can try if(string is null) - is instead of ==. Though usually in D, I just if(string.length == 0) and treat empty and null the same way. This is likely not what you want, it's generally not important where a string is

Re: Creating a microcontroller startup file

2015-04-09 Thread Artur Skawina via Digitalmars-d-learn
On 04/08/15 18:10, Jens Bauer via Digitalmars-d-learn wrote: On Wednesday, 8 April 2015 at 11:17:12 UTC, Mike wrote: On Tuesday, 7 April 2015 at 20:33:26 UTC, Jens Bauer wrote: enum weak = gcc.attribute.attribute(weak); enum isrDefault = gcc.attribute.attribute(alias, defaultHandler);

Re: Is it any faster to read array slices than just elements of an array?

2015-04-09 Thread Marco Leise via Digitalmars-d-learn
Am Wed, 08 Apr 2015 17:01:43 + schrieb ZILtoid1991 ziltoidtheomnic...@gmail.com: While I technically finished the 0.2 version of my graphics engine which has a reasonable speed at low internal resolutions and with only a couple of sprites, but it still gets bottlenecked a lot. First

Re: return the other functions of the void main()

2015-04-09 Thread John Colvin via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:04:00 UTC, Dennis Ritchie wrote: Hi, Is it allowed in D similar designs? void main() { import std.stdio; return writeln(Hello, world!); } Yes, because writeln returns nothing, but why would you do that? Just put the return on the next line,

Re: Managing memory usage at Compile Time with DMD

2015-04-09 Thread John Colvin via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:05:22 UTC, John Colvin wrote: On Thursday, 9 April 2015 at 10:23:06 UTC, wobbles wrote: On Thursday, 9 April 2015 at 10:04:09 UTC, John Colvin wrote: On Thursday, 9 April 2015 at 09:49:39 UTC, wobbles wrote: Another possibilty I was looking at was to write a

Re: Managing memory usage at Compile Time with DMD

2015-04-09 Thread John Colvin via Digitalmars-d-learn
On Thursday, 9 April 2015 at 10:23:06 UTC, wobbles wrote: On Thursday, 9 April 2015 at 10:04:09 UTC, John Colvin wrote: On Thursday, 9 April 2015 at 09:49:39 UTC, wobbles wrote: Another possibilty I was looking at was to write a tool that will spit out all combinations at runtime, and then

Re: return the other functions of the void main()

2015-04-09 Thread Rikki Cattermole via Digitalmars-d-learn
On 9/04/2015 11:03 p.m., Dennis Ritchie wrote: Hi, Is it allowed in D similar designs? void main() { import std.stdio; return writeln(Hello, world!); } Sure when: import std.traits : ReturnType; import std.stdio : writeln; static assert(is(ReturnType!writeln == int));

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
By the way, I am using DMD64 D Compiler v2.067.0 on Ubuntu 14.04.

Escape a string ?

2015-04-09 Thread Temtaime via Digitalmars-d-learn
Hi ! I wonder how to escape a string in phobos ? For example auto a = [ fooo\nbar ]; auto b = format(%(%s%), a); gives b: fooo\nbar Is there any other function to escape string? I'm looking for something that doesn't require to make an array at first. For example is there string

Re: return the other functions of the void main()

2015-04-09 Thread bearophile via Digitalmars-d-learn
Jack Applegame: writeln(a.find(4).empty ? No : Yes); canFind? Bye, bearophile

Re: return the other functions of the void main()

2015-04-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 9 April 2015 at 12:57:26 UTC, Jack Applegame wrote: I quite often have to write similar designs: - import std.stdio; void main() { auto a = [ 1, 2, 3, 4, 5 ]; foreach (e; a) { if (e == 4) { writeln(Yes);

Re: return the other functions of the void main()

2015-04-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 9 April 2015 at 16:55:00 UTC, John Colvin wrote: Try running your code somewhere where you can actually see the output properly. RUNTIME_ERROR isn't something I recognise from D. Operates a code normally, but still gives the error: http://ideone.com/kDHMk5

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 14:16:00 UTC, tcak wrote: By the way, I am using DMD64 D Compiler v2.067.0 on Ubuntu 14.04. I have Archlinux DMD64 D Compiler v2.067.0 and it works OK for me.

Re: How to interface with C++ code or dll?

2015-04-09 Thread Suliman via Digitalmars-d-learn
http://stackoverflow.com/questions/29541229/d-how-to-use-binding-to-c-lib-with-d

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 12:06:49 UTC, Daniel Kozák wrote: On Thu, 09 Apr 2015 11:45:30 + tcak via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Can you post full example somewhere, this code works ok for me: import std.stdio; import std.datetime; class Response {

Re: using vibe.d to parse json

2015-04-09 Thread Laeeth Isharc via Digitalmars-d-learn
On Tuesday, 7 April 2015 at 22:15:13 UTC, Sönke Ludwig wrote: Am 26.03.2015 um 02:38 schrieb Laeeth Isharc: 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.

Re: return the other functions of the void main()

2015-04-09 Thread John Colvin via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:38:26 UTC, Rikki Cattermole wrote: On 9/04/2015 11:22 p.m., John Colvin wrote: On Thursday, 9 April 2015 at 11:07:05 UTC, Rikki Cattermole wrote: On 9/04/2015 11:03 p.m., Dennis Ritchie wrote: Hi, Is it allowed in D similar designs? void main() { import