Re: How to organize using modules?

2013-12-30 Thread TheFlyingFiddle
2) You can import many classes using the '*' syntax. You don't use the * syntax. Just stop after the module name.

Re: How to organize using modules?

2013-12-30 Thread TheFlyingFiddle
On Tuesday, 31 December 2013 at 06:01:21 UTC, Afshin wrote: Is it possible to describe modules in terms of packages (as found in Java)? The features that Java packages have that I can't seem to get in D are: 1) You can have classes that are in the same package, but kept in separate files. 2)

How to organize using modules?

2013-12-30 Thread Afshin
Is it possible to describe modules in terms of packages (as found in Java)? The features that Java packages have that I can't seem to get in D are: 1) You can have classes that are in the same package, but kept in separate files. 2) You can import many classes using the '*' syntax. Is this p

Re: A better way to write this function? (style question)

2013-12-30 Thread Thomas Gann
Thanks for all your replies, guys! I have done some further research in the meantime and I have found out that I am, in fact, an idiot. There is actually a standard library function that does exactly what I am trying to do! As it turns out, std.string.split(): 1) It automatically discards emp

Re: Possible bug - should the following code cause an access violation exception?

2013-12-30 Thread Ali Çehreli
On 12/30/2013 04:55 PM, Afshin wrote: Thanks Ali. I uninstalled 2.63.x. Installed the 2.64.2. I compiled and ran the test, and surely enough there were no problems. However, when I build using Visual D environment, the problem persists. Microsoft Visual Studio 2010 Ultimate. Visual D plugin.

Re: Possible bug - should the following code cause an access violation exception?

2013-12-30 Thread Afshin
Thanks Ali. I uninstalled 2.63.x. Installed the 2.64.2. I compiled and ran the test, and surely enough there were no problems. However, when I build using Visual D environment, the problem persists. Microsoft Visual Studio 2010 Ultimate. Visual D plugin. Thankfully, there is a simple work

Re: Debug/reduce stack overflow in DMD on Windows

2013-12-30 Thread Jacob Carlborg
On 2013-12-30 23:21, Vladimir Panteleev wrote: You could try reducing the bug using DustMite, and this helper: Thanks, DustMite was able to find a reduced test case. It was this little piece of code: enum : DWORD { DWORD = REG_DWORD } -- /Jacob Carlborg

Re: Recursive lambda functions?

2013-12-30 Thread Timon Gehr
On 12/30/2013 11:50 PM, Meta wrote: enum factorial5=(function int(a)=>a==0?1:a*__traits(parent,{})(a-1))(5); (In D, you need to specify the return type for a recursive function declaration. If one doesn't here, DMD crashes, which is a bug. https://d.puremagic.com/issues/show_bug.cgi?id=11848)

Re: A better way to write this function? (style question)

2013-12-30 Thread bearophile
Thomas Gann: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowercase, and then return an array of words that are generated by splitting the string up by whitespace. Take a lo

Re: Recursive lambda functions?

2013-12-30 Thread Meta
On Monday, 30 December 2013 at 21:58:29 UTC, Timon Gehr wrote: On 12/30/2013 10:15 PM, Ilya Yaroshenko wrote: On Monday, 30 December 2013 at 12:24:28 UTC, lomereiter wrote: Use Y combinator? http://forum.dlang.org/thread/mailman.157.1385247528.2552.digitalmars-d-le...@puremagic.com#post-l6rgfq:

Re: A better way to write this function? (style question)

2013-12-30 Thread John Colvin
On Monday, 30 December 2013 at 22:38:43 UTC, Brad Anderson wrote: On Monday, 30 December 2013 at 22:30:02 UTC, John Colvin wrote: On Monday, 30 December 2013 at 22:17:21 UTC, John Colvin wrote: On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I

Re: A better way to write this function? (style question)

2013-12-30 Thread Brad Anderson
On Monday, 30 December 2013 at 22:30:02 UTC, John Colvin wrote: On Monday, 30 December 2013 at 22:17:21 UTC, John Colvin wrote: On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert al

Re: A better way to write this function? (style question)

2013-12-30 Thread Brad Anderson
On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowercase, and then return an array of words that are generated by s

Re: A better way to write this function? (style question)

2013-12-30 Thread John Colvin
On Monday, 30 December 2013 at 22:17:21 UTC, John Colvin wrote: On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowe

Re: Debug/reduce stack overflow in DMD on Windows

2013-12-30 Thread Vladimir Panteleev
On Monday, 30 December 2013 at 13:04:38 UTC, Jacob Carlborg wrote: I've ported one of my projects[1] from D1 to D2 and it works perfectly fine on Posix. Now when I try to compile the code on Windows I get a stack overflow. I really suck at Windows development, I don't even know where to start.

Re: Recursive lambda functions?

2013-12-30 Thread Meta
On Monday, 30 December 2013 at 21:15:43 UTC, Ilya Yaroshenko wrote: On Monday, 30 December 2013 at 12:24:28 UTC, lomereiter wrote: Use Y combinator? http://forum.dlang.org/thread/mailman.157.1385247528.2552.digitalmars-d-le...@puremagic.com#post-l6rgfq:24g5o:241:40digitalmars.com This is not l

Re: A better way to write this function? (style question)

2013-12-30 Thread John Colvin
On Monday, 30 December 2013 at 21:40:58 UTC, Thomas Gann wrote: I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowercase, and then return an array of words that are generated by s

Re: Recursive lambda functions?

2013-12-30 Thread Timon Gehr
On 12/30/2013 10:15 PM, Ilya Yaroshenko wrote: On Monday, 30 December 2013 at 12:24:28 UTC, lomereiter wrote: Use Y combinator? http://forum.dlang.org/thread/mailman.157.1385247528.2552.digitalmars-d-le...@puremagic.com#post-l6rgfq:24g5o:241:40digitalmars.com This is not lambda =( I want som

Re: Recursive lambda functions?

2013-12-30 Thread lomereiter
On Monday, 30 December 2013 at 21:15:43 UTC, Ilya Yaroshenko wrote: I want something like enum factrorial5 = (a => a == 0 ? 1 : a * __lambda(a-1))(5); //Recursive pure lambda function That isn't supported in D. And cases where this would be useful are too rare to add complexity to the languag

A better way to write this function? (style question)

2013-12-30 Thread Thomas Gann
I've written a Markov bot in D, and I have function whose job it is to take an input string, convert all newline characters to spaces and all uppercase letters to lowercase, and then return an array of words that are generated by splitting the string up by whitespace. Here is the function is qu

Re: Recursive lambda functions?

2013-12-30 Thread Ilya Yaroshenko
On Monday, 30 December 2013 at 12:24:28 UTC, lomereiter wrote: Use Y combinator? http://forum.dlang.org/thread/mailman.157.1385247528.2552.digitalmars-d-le...@puremagic.com#post-l6rgfq:24g5o:241:40digitalmars.com This is not lambda =( I want something like enum factrorial5 = (a => a == 0 ? 1

Re: boilerplate generation

2013-12-30 Thread Dicebot
On Monday, 30 December 2013 at 20:04:00 UTC, Carl Sturtivant wrote: Apologies, I was perhaps unclear. I'm just wondering if pragma(mangle) is guaranteed to be implemented, so I can safely put it in portable D. It's not mentioned in http://dlang.org/pragma.html Nature of reference compiler is

Re: Debug/reduce stack overflow in DMD on Windows

2013-12-30 Thread Jacob Carlborg
On 2013-12-30 17:19, Benjamin Thaut wrote: Compile in 64-bit and use Visual Studio or Visual Studio Express to debug the application. If you want to compile in 32-bit you will need to run cv2pdb on the generated exectuable before debugging with visual studio. cv2pdb is part of VisualD which I re

Re: boilerplate generation

2013-12-30 Thread Carl Sturtivant
On Monday, 30 December 2013 at 17:46:57 UTC, John Colvin wrote: It's unrelated to the target architecture, it's just for naming. See dlang.org/abi.html Apologies, I was perhaps unclear. I'm just wondering if pragma(mangle) is guaranteed to be implemented, so I can safely put it in portable D

Re: module std.regex

2013-12-30 Thread Benji
On Monday, 30 December 2013 at 19:27:43 UTC, Dmitry Olshansky wrote: 30-Dec-2013 22:08, Benji пишет: Hello, when I try to run following code: import std.stdio; import std.net.curl; void main() { writeln("dlang.org"); } I get following error: Fatal Error while loading '/usr/lib/x86_64-li

Re: module std.regex

2013-12-30 Thread Dmitry Olshansky
30-Dec-2013 22:08, Benji пишет: Hello, when I try to run following code: import std.stdio; import std.net.curl; void main() { writeln("dlang.org"); } I get following error: Fatal Error while loading '/usr/lib/x86_64-linux-gnu/libphobos2.so.0.64': The module 'std.regex' is already de

Re: Slices, appending to arbitrary position

2013-12-30 Thread H. S. Teoh
On Mon, Dec 30, 2013 at 06:40:24PM +, Dfr wrote: > > Thank you for replies, i think here i can use assoc array, but > sometimes it is not suitable because it is not preserve order. Maybe you can use std.container.RedBlackTree instead? That will preserve order (but at the cost of asymptoticall

Re: module std.regex

2013-12-30 Thread Benji
On Monday, 30 December 2013 at 18:36:24 UTC, John Colvin wrote: On Monday, 30 December 2013 at 18:08:42 UTC, Benji wrote: Hello, when I try to run following code: import std.stdio; import std.net.curl; void main() { writeln("dlang.org"); } I get following error: Fatal Error while loa

Re: Slices, appending to arbitrary position

2013-12-30 Thread Dfr
Thank you for replies, i think here i can use assoc array, but sometimes it is not suitable because it is not preserve order. On Monday, 30 December 2013 at 18:19:54 UTC, Dfr wrote: This simple example: string[] a; a[10] = "hello"; Gives me: core.exception.RangeError: Range violation I k

Re: module std.regex

2013-12-30 Thread John Colvin
On Monday, 30 December 2013 at 18:08:42 UTC, Benji wrote: Hello, when I try to run following code: import std.stdio; import std.net.curl; void main() { writeln("dlang.org"); } I get following error: Fatal Error while loading '/usr/lib/x86_64-linux-gnu/libphobos2.so.0.64': Th

Re: Slices, appending to arbitrary position

2013-12-30 Thread Jakob Ovrum
On Monday, 30 December 2013 at 18:19:54 UTC, Dfr wrote: This simple example: string[] a; a[10] = "hello"; Gives me: core.exception.RangeError: Range violation I know about this way: string[] a; a = new string[11]; a[10] = "hello"; But what if i need do this many times with the same array lik

Re: Slices, appending to arbitrary position

2013-12-30 Thread bearophile
Dfr: string[] a; a[10] = "hello"; Gives me: core.exception.RangeError: Range violation Because 'a' has length 0, so the position with index 11 doesn't exists in the array. By the way, this is not an "appending", it's a (failed) assignment. I know about this way: string[] a; a = new s

Re: Slices, appending to arbitrary position

2013-12-30 Thread Chris Cain
On Monday, 30 December 2013 at 18:19:54 UTC, Dfr wrote: This simple example: string[] a; a[10] = "hello"; Gives me: core.exception.RangeError: Range violation I know about this way: string[] a; a = new string[11]; a[10] = "hello"; But what if i need do this many times with the same array lik

Slices, appending to arbitrary position

2013-12-30 Thread Dfr
This simple example: string[] a; a[10] = "hello"; Gives me: core.exception.RangeError: Range violation I know about this way: string[] a; a = new string[11]; a[10] = "hello"; But what if i need do this many times with the same array like this: a[10] = "a"; ... a[1] = "b"; .. a[1000] = "c";

module std.regex

2013-12-30 Thread Benji
Hello, when I try to run following code: import std.stdio; import std.net.curl; void main() { writeln("dlang.org"); } I get following error: Fatal Error while loading '/usr/lib/x86_64-linux-gnu/libphobos2.so.0.64': The module 'std.regex' is already defined in './maina'. Segme

Re: boilerplate generation

2013-12-30 Thread John Colvin
On Monday, 30 December 2013 at 17:33:13 UTC, Carl Sturtivant wrote: On Monday, 30 December 2013 at 04:35:34 UTC, Dicebot wrote: It can be forced by pragma(mangle) though. Updated code: [...] Never heard of pragma(mangle)! Very useful. What role does it play in D? Is it guaranteed implemented

Re: boilerplate generation

2013-12-30 Thread Carl Sturtivant
On Monday, 30 December 2013 at 04:35:34 UTC, Dicebot wrote: It can be forced by pragma(mangle) though. Updated code: [...] Never heard of pragma(mangle)! Very useful. What role does it play in D? Is it guaranteed implemented on x86 or amd64? Thanks for the answer, very nice.

Re: Debug/reduce stack overflow in DMD on Windows

2013-12-30 Thread Benjamin Thaut
Am 30.12.2013 14:04, schrieb Jacob Carlborg: I've ported one of my projects[1] from D1 to D2 and it works perfectly fine on Posix. Now when I try to compile the code on Windows I get a stack overflow. I really suck at Windows development, I don't even know where to start. Which debugger should I

Re: Possible bug - should the following code cause an access violation exception?

2013-12-30 Thread Ali Çehreli
On 12/29/2013 10:38 PM, Afshin wrote: module test; class Foo { public static ulong next = 0; public static ulong getNext() { return next++; } } void main() { Foo.getNext(); } /* The next++ is the culprit. Using a ++next does not throw an exception. */ Must have

Debug/reduce stack overflow in DMD on Windows

2013-12-30 Thread Jacob Carlborg
I've ported one of my projects[1] from D1 to D2 and it works perfectly fine on Posix. Now when I try to compile the code on Windows I get a stack overflow. I really suck at Windows development, I don't even know where to start. Which debugger should I use that can handle the debug format DMD is

Re: Recursive lambda functions?

2013-12-30 Thread TheFlyingFiddle
On Monday, 30 December 2013 at 11:23:39 UTC, Ilya Yaroshenko wrote: Hello! Is there any ability to lambda function call itself? Is it correct feature for D? Best Regards, Ilya Well it's possible to do this (sort of). //You could for instance define the Factorial function like this. int del

Re: Recursive lambda functions?

2013-12-30 Thread lomereiter
Use Y combinator? http://forum.dlang.org/thread/mailman.157.1385247528.2552.digitalmars-d-le...@puremagic.com#post-l6rgfq:24g5o:241:40digitalmars.com

Recursive lambda functions?

2013-12-30 Thread Ilya Yaroshenko
Hello! Is there any ability to lambda function call itself? Is it correct feature for D? Best Regards, Ilya

Re: How to delete dynamic array ?

2013-12-30 Thread Jakob Ovrum
On Monday, 30 December 2013 at 06:52:20 UTC, Ilya Yaroshenko wrote: case 1: delete ar; case 2: ar.destroy(); case 3: GC.free(ar.ptr); case 4: ar = null;// (assumed that ar is only one pointer to the same array) What is the difference? How to free memory to the system immediately? It dep

Re: How to delete dynamic array ?

2013-12-30 Thread Dicebot
Answer will make more sense if ar is assumed to be any heap-allocated object, not just dynamic array. On Monday, 30 December 2013 at 06:52:20 UTC, Ilya Yaroshenko wrote: case 1: delete ar; Deprecated. Used to call destructor and GC.free after that case 2: ar.destroy(); Current solution

Re: How to delete dynamic array ?

2013-12-30 Thread bearophile
Ilya Yaroshenko: case 1: delete ar; It's deprecated. case 4: ar = null;// (assumed that ar is only one pointer to the same array) It's the simpler way. How to free memory to the system immediately? What is your use case? Bye, bearophile