Re: AA.clear()?

2013-02-16 Thread Nick Sabalausky
On Sat, 16 Feb 2013 16:58:27 -0800 "H. S. Teoh" wrote: > On Sat, Feb 16, 2013 at 07:20:29PM -0500, Nick Sabalausky wrote: > > Didn't there used to be an AA.clear (maybe a different name?) to > > clear an assoc array? There doesn't appear to be any mention of it > > here: > > > > http://dlang.org

Re: Can remove AA elements during foreach?

2013-02-16 Thread Steven Schveighoffer
On Sat, 16 Feb 2013 18:59:59 -0500, Nick Sabalausky wrote: Is this both legal and safe?: foreach(key; assocArray) if(key != "foobar") assocArray.remove("foobar"); If not, then what about this?: foreach(key; assocArray.byKey()) if(key != "foobar") assocArray.

Re: AA.clear()?

2013-02-16 Thread Jonathan M Davis
On Saturday, February 16, 2013 16:58:27 H. S. Teoh wrote: > On Sat, Feb 16, 2013 at 07:20:29PM -0500, Nick Sabalausky wrote: > > Didn't there used to be an AA.clear (maybe a different name?) to clear > > an assoc array? There doesn't appear to be any mention of it here: > > > > http://dlang.org/ha

Re: Can remove AA elements during foreach?

2013-02-16 Thread Nick Sabalausky
On Sat, 16 Feb 2013 16:20:30 -0800 "H. S. Teoh" wrote: > On Sat, Feb 16, 2013 at 06:59:59PM -0500, Nick Sabalausky wrote: > > Is this both legal and safe?: > > > > foreach(key; assocArray) > > if(key != "foobar") > > assocArray.remove("foobar"); > > > > If not, then what about t

Re: AA.clear()?

2013-02-16 Thread H. S. Teoh
On Sat, Feb 16, 2013 at 07:20:29PM -0500, Nick Sabalausky wrote: > Didn't there used to be an AA.clear (maybe a different name?) to clear > an assoc array? There doesn't appear to be any mention of it here: > > http://dlang.org/hash-map > > Did something happen to it, or am I just remembering wro

Re: AA.clear()?

2013-02-16 Thread Jonathan M Davis
On Saturday, February 16, 2013 19:20:29 Nick Sabalausky wrote: > Didn't there used to be an AA.clear (maybe a different name?) to clear > an assoc array? There doesn't appear to be any mention of it here: > > http://dlang.org/hash-map > > Did something happen to it, or am I just remembering wrong

Re: Can remove AA elements during foreach?

2013-02-16 Thread H. S. Teoh
On Sat, Feb 16, 2013 at 06:59:59PM -0500, Nick Sabalausky wrote: > Is this both legal and safe?: > > foreach(key; assocArray) > if(key != "foobar") > assocArray.remove("foobar"); > > If not, then what about this?: > > foreach(key; assocArray.byKey()) > if(key != "foobar")

Can remove AA elements during foreach?

2013-02-16 Thread Nick Sabalausky
Is this both legal and safe?: foreach(key; assocArray) if(key != "foobar") assocArray.remove("foobar"); If not, then what about this?: foreach(key; assocArray.byKey()) if(key != "foobar") assocArray.remove("foobar");

Re: Issues with std.regex

2013-02-16 Thread FG
On 2013-02-16 22:36, MrAppleseed wrote: Perhaps try this: "[ 0-9a-zA-Z.*=+-;()\"\'\\[\\]<>,{}^#/\\]" I made the changes you suggested above, and although it compiled fine, on the first run I got a similar error: std.regex.RegexException@/usr/include/dmd/phobos/std/regex.d(1942): unexpected en

Re: Issues with std.regex

2013-02-16 Thread jerro
Pattern with error: `[ 0-9a-zA-Z.*=+-;()"'\[\]<>,{}^#/\]` <--HERE-- `` The problem here is that you have \ right before the ] at the end of the string. Because it is preceeded by \, ] is interpretted as a character you are matching on, not as a closing bracket for the initial [. If you want t

Re: Issues with std.regex

2013-02-16 Thread jerro
std.regex.RegexException@/usr/include/dmd/phobos/std/regex.d(1942): wrong CodepointSet Pattern with error: `[ 0-9a-zA-Z.*=+-;()"'[]` <--HERE-- `<>,{}^#/\\]` (Entire error here: http://pastebin.com/Su9XzbXW) You need to put \ in front of [ or ] if you want to match those two characters. The r

Re: Callbacks or similar?

2013-02-16 Thread Lemonfiend
On Saturday, 16 February 2013 at 21:31:05 UTC, Jonathan M Davis wrote: On Saturday, February 16, 2013 22:24:19 Lemonfiend wrote: On Saturday, 16 February 2013 at 21:03:54 UTC, Dicebot wrote: > http://dlang.org/expression.html#FunctionLiteral > > Function parameters/variables are declared in D u

Re: Issues with std.regex

2013-02-16 Thread MrAppleseed
On Saturday, 16 February 2013 at 20:33:15 UTC, FG wrote: On 2013-02-16 21:22, MrAppleseed wrote: auto reg = regex("[ 0-9a-zA-Z.*=+-;()\"\'\[\]<>,{}^#/\\]"); When I try to run the code above, I get: parser.d(64): Error: undefined escape sequence \[ parser.d(64): Error: undefined escape sequence

Re: Issues with std.regex

2013-02-16 Thread MrAppleseed
On Saturday, 16 February 2013 at 20:35:48 UTC, H. S. Teoh wrote: On Sat, Feb 16, 2013 at 09:22:07PM +0100, MrAppleseed wrote: Hey all, I'm currently trying to port my small toy language I invented awhile back in Java to D. However, a main part of my lexical analyzer was regular expression mat

Re: Callbacks or similar?

2013-02-16 Thread Jonathan M Davis
On Saturday, February 16, 2013 22:24:19 Lemonfiend wrote: > On Saturday, 16 February 2013 at 21:03:54 UTC, Dicebot wrote: > > http://dlang.org/expression.html#FunctionLiteral > > > > Function parameters/variables are declared in D using > > "ReturnType function(ParameterTypes) symbol". "function"

Re: Callbacks or similar?

2013-02-16 Thread Lemonfiend
On Saturday, 16 February 2013 at 21:03:54 UTC, Dicebot wrote: http://dlang.org/expression.html#FunctionLiteral Function parameters/variables are declared in D using "ReturnType function(ParameterTypes) symbol". "function" is a keyword here, it can be swapped for "delegate" to get, em, delegat

Re: Callbacks or similar?

2013-02-16 Thread Dicebot
http://dlang.org/expression.html#FunctionLiteral Function parameters/variables are declared in D using "ReturnType function(ParameterTypes) symbol". "function" is a keyword here, it can be swapped for "delegate" to get, em, delegates. In your case something like "void function(int) callback"

Callbacks or similar?

2013-02-16 Thread Lemonfiend
Hi, I'm looking for a way to do call different functions within a loop, so I won't have to write multiple functions with the same looping mechanism. I'm not sure if I'm explaing this very well, but this very simple example should clarify: void foo(int[] arr) { foreach(int val; arr)

Re: Issues with std.regex

2013-02-16 Thread Namespace
As long as there is \" I get the same error.

Re: Issues with std.regex

2013-02-16 Thread H. S. Teoh
On Sat, Feb 16, 2013 at 09:22:07PM +0100, MrAppleseed wrote: > Hey all, > > I'm currently trying to port my small toy language I invented awhile > back in Java to D. However, a main part of my lexical analyzer was > regular expression matching, which I've been having issues with in > D. The regex

Re: Issues with std.regex

2013-02-16 Thread FG
On 2013-02-16 21:22, MrAppleseed wrote: auto reg = regex("[ 0-9a-zA-Z.*=+-;()\"\'\[\]<>,{}^#/\\]"); When I try to run the code above, I get: parser.d(64): Error: undefined escape sequence \[ parser.d(64): Error: undefined escape sequence \] When I remove the escaped characters (turning my regex

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
Jos van Uden: Yes, that was your original suggestion, but I didn't quite understand it, When you don't understand something I say, please ask for more info :-) You would reverse the left array when printing, is that correct? Right, the second half of the tape keeps the cells in reverse

Issues with std.regex

2013-02-16 Thread MrAppleseed
Hey all, I'm currently trying to port my small toy language I invented awhile back in Java to D. However, a main part of my lexical analyzer was regular expression matching, which I've been having issues with in D. The regex expression in question is as follows: [ 0-9a-zA-Z.*=+-;()\"\'\[\]<>

Re: A little of coordination for Rosettacode

2013-02-16 Thread Jos van Uden
On 16-2-2013 19:55, bearophile wrote: There is a way to make the D code faster: prepending a cell in left() is a slow operation: void right() pure nothrow { this.position++; if (this.position == this.tape.length) this.tape ~= this.blank; } void left() pure nothrow { if

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
There is a way to make the D code faster: prepending a cell in left() is a slow operation: void right() pure nothrow { this.position++; if (this.position == this.tape.length) this.tape ~= this.blank; } void left() pure nothrow { if (this.position == 0) this.tape = th

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
Jos van Uden: I added that precondition reluctantly, that's why its short :-). I really feel that input validation should be done elsewhere. A full validation needs to be done somewhere :-) I was thinking about adding a factory method to the UTM that accepts a string array, parses and vali

Re: A little of coordination for Rosettacode

2013-02-16 Thread Jos van Uden
On 16-2-2013 18:23, bearophile wrote: The version you have put in Rosettacode is good, I have just added some missing tests at the beginning of the UTM constructor. I added that precondition reluctantly, that's why its short :-). I really feel that input validation should be done elsewhere.

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
The version you have put in Rosettacode is good, I have just added some missing tests at the beginning of the UTM constructor. Annotations like this are reminders of DMD bugs/limits that hopefully we'll be fixed/lifeted: foreach (/*const*/ s, const rule; aa) { While this annotation: alias St

Re: How to interface to a C struct with volatile variables?

2013-02-16 Thread Ben Davis
On 16/02/2013 15:19, Jacob Carlborg wrote: On 2013-02-16 15:13, Ben Davis wrote: As for 'volatile', there's some info at http://dlang.org/deprecate.html#volatile about how it used to be available for marking statements as 'do not optimise field accesses'. The corrective action listed there is to

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
with this little program I have found two new compiler bugs, I will put it in Bugzilla later. http://d.puremagic.com/issues/show_bug.cgi?id=9520 http://d.puremagic.com/issues/show_bug.cgi?id=9521 Bye, bearophile

Re: How to interface to a C struct with volatile variables?

2013-02-16 Thread Jacob Carlborg
On 2013-02-16 15:13, Ben Davis wrote: On 16/02/2013 03:54, Charles Hixson wrote: Does D have an equivalent to the C marking of volatile? Currently I'm just going to try removing all variables from the struct, as it's never declared in D or accessed from within D, and I just want to avoid cast(v

Re: Working with modules

2013-02-16 Thread Jacob Carlborg
On 2013-02-16 05:19, Jeremy DeHaan wrote: That is really cool! I'll look into this more, but I am using an IDE which would get angry if I included them in my project as .d files and didn't put in a module name, but I think you're on to something here. There's also template mixins that could he

Re: Working with modules

2013-02-16 Thread Jacob Carlborg
On 2013-02-16 15:12, Ali Çehreli wrote: I don't think it is better than any other solution. I got reminded of this possibility; that's all. :) Fair enough. :) -- /Jacob Carlborg

Re: For DLLs, what does export actually do?

2013-02-16 Thread Andrej Mitrovic
On 2/16/13, Ben Davis wrote: > Certainly DllMain > isn't appearing in my export table, yet I've established (by calling > MessageBoxA from inside DllMain - that was brave of me, wasn't it? :P) > that it is being called. :) It's handled by the compiler itself, e.g.: https://github.com/D-Programmin

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
By the way, with this little program I have found two new compiler bugs, I will put it in Bugzilla later. Bye, bearophile

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
Jos van Uden: This is what I have now (incorperated part of your suggestions): http://codepad.org/wjaSgppT It looks good. It's not a strongly typed code (because states are just chars), and it's not much flexible because UTM is not templated on Symbol and State, but for this task it's OK.

Re: How to interface to a C struct with volatile variables?

2013-02-16 Thread Ben Davis
On 16/02/2013 03:54, Charles Hixson wrote: Does D have an equivalent to the C marking of volatile? Currently I'm just going to try removing all variables from the struct, as it's never declared in D or accessed from within D, and I just want to avoid cast(void*)s, but I may need to access someth

Re: Working with modules

2013-02-16 Thread Ali Çehreli
On 02/16/2013 04:58 AM, Jacob Carlborg wrote: On 2013-02-16 05:14, Ali Çehreli wrote: mixin (import ("part_of_my_module.d")); mixin (import ("another_part_of_my_module.d")); How is that better than public imports. You'll get access to private declarations but besides that. I don't think it

Re: For DLLs, what does export actually do?

2013-02-16 Thread Ben Davis
On 11/02/2013 16:06, Regan Heath wrote: On Sun, 10 Feb 2013 12:36:38 -, Ben Davis wrote: DllMain is a weird one - it creates all sorts of linker errors if I try it with extern(C) instead of extern(Windows) (which is different from the other methods, which compile fine with extern(C) and the

Re: A little of coordination for Rosettacode

2013-02-16 Thread Jos van Uden
On 16-2-2013 14:04, bearophile wrote: Jos van Uden: BTW, the reason I used a class is that it forces you to instantiate through the constructor. One possible solution: http://codepad.org/9PO8hpI7 Initializing the struct that way didn't work because I changed the AA back to nested. This i

Re: std.container.RedBlackTree versus C++ std::set

2013-02-16 Thread Dan
On Friday, 15 February 2013 at 20:58:30 UTC, Jonathan M Davis wrote: I should probably add that bringing up discussions on how to solve problems in the language can be of benefit, because they often result in good discussions that help lead toward a solution, and that can lead towards that so

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
Jos van Uden: BTW, the reason I used a class is that it forces you to instantiate through the constructor. One possible solution: http://codepad.org/9PO8hpI7 Bye, bearophile

Re: Working with modules

2013-02-16 Thread Jacob Carlborg
On 2013-02-16 05:14, Ali Çehreli wrote: mixin (import ("part_of_my_module.d")); mixin (import ("another_part_of_my_module.d")); How is that better than public imports. You'll get access to private declarations but besides that. -- /Jacob Carlborg

Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
Jos van Uden: It's fine, but we need another write at the end of run otherwise the final state doesn't get written. OK. Feel free to fix the code: http://codepad.org/MvpSET1I Writing good enough code is an iterative process... And this code will probably need few more iterations. I'm thi

Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-16 Thread Jos van Uden
On 16-2-2013 8:58, qznc wrote: On Saturday, 16 February 2013 at 06:58:01 UTC, qznc wrote: On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden wrote: On 5-2-2013 20:45, Jos van Uden wrote: By the way, I think 'Qznc' may want to have a look at 'The dining philosophers': http://rosettac

Re: A little of coordination for Rosettacode

2013-02-16 Thread Jos van Uden
On 16-2-2013 3:34, bearophile wrote: A first revision, do you like the toString? http://codepad.org/qhH2XpMx It's fine, but we need another write at the end of run otherwise the final state doesn't get written. The modified code contains still an enum that gets converted to char and then t

Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile
monarch_dodra: I'm reporting it instead of correcting it directly, so as to better explain how and why. Thank you, some bugs are interesting. I will change the code. Bye, bearophile

Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-16 Thread monarch_dodra
On Saturday, 16 February 2013 at 07:58:56 UTC, qznc wrote: On Saturday, 16 February 2013 at 06:58:01 UTC, qznc wrote: On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden wrote: On 5-2-2013 20:45, Jos van Uden wrote: By the way, I think 'Qznc' may want to have a look at 'The dining ph

Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-16 Thread qznc
On Saturday, 16 February 2013 at 06:58:01 UTC, qznc wrote: On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden wrote: On 5-2-2013 20:45, Jos van Uden wrote: By the way, I think 'Qznc' may want to have a look at 'The dining philosophers': http://rosettacode.org/wiki/Dining_philosopher