class invariants and property declarations

2011-02-16 Thread Michael Engelhardt
Hi, I just have started diving in D. Exploring the contract feature I stumbled upon the fact that a class invariant does not apply to properties: import std.stdio; void main(string[] args) { Time t = new Time(); t.hours = 24; // works; why? writeln(t.hours is , t.hours);

Re: class invariants and property declarations

2011-02-16 Thread Dmitry Olshansky
On 16.02.2011 11:03, Michael Engelhardt wrote: Hi, I just have started diving in D. Exploring the contract feature I stumbled upon the fact that a class invariant does not apply to properties: Welcome on board :) Invariant gets called on every public method call (at begin end if I'm not

Re: Context-Free Grammars? What about arrays?

2011-02-16 Thread %u
Yes, they just happen to look identical: but that's the crux: How it looks is the *only* thing that parser/grammar are concerned with. If it worked like this: Array Decl ::= Type '[' Ident ']' Ident ';' Assoc Array Decl ::= Type '[' Ident ']' Ident ';' ...*Then* it would no longer be

Re: Isn't using find with retro awkward?

2011-02-16 Thread spir
On 02/16/2011 07:22 AM, Denis Koroskin wrote: On Tue, 15 Feb 2011 06:35:21 +0300, Andrej Mitrovic n...@none.none wrote: import std.stdio, std.algorithm, std.range; void main() { writeln( find([5, 1, 2, 3, 4, 5, 1], 5) ); writeln( find(retro([5, 1, 2, 3, 4, 5, 1]), 5) ); } Output: [5, 1, 2,

intrinsic min and max for ints

2011-02-16 Thread Dominic Jones
Hello, Is there a library function for min/max for integers. I would rather not use the ?-operator, it's rather clumsy. I looked in the standard lib and only found f(min|max). Thank you, Dominic Jones

Re: intrinsic min and max for ints

2011-02-16 Thread Mafi
Am 16.02.2011 10:54, schrieb Dominic Jones: Hello, Is there a library function for min/max for integers. I would rather not use the ?-operator, it's rather clumsy. I looked in the standard lib and only found f(min|max). Thank you, Dominic Jones They're in 'std.algorithm'. They work for all

Re: Git library for checkouts?

2011-02-16 Thread David Nadlinger
On 2/15/11 10:09 PM, Lars T. Kyllingstad wrote: https://github.com/schacon/libgit That'd rather be http://libgit2.github.com/, though I have no idea how usable it is already. David

regex escapes

2011-02-16 Thread spir
Hello, Which characters are to be escaped: * inside [] classes * outside such classes ? Also, is there for D regexes a free form format (where whitespace can be used to present formats more legibly, but must be escaped as literals)? Denis -- _ vita es estrany spir.wikidot.com

Re: regex escapes

2011-02-16 Thread Alex Folland
On 2011-02-16 5:48, spir wrote: Hello, Which characters are to be escaped: * inside [] classes * outside such classes ? Also, is there for D regexes a free form format (where whitespace can be used to present formats more legibly, but must be escaped as literals)? Denis This is a comment

Re: Git library for checkouts?

2011-02-16 Thread Jacob Carlborg
On 2011-02-16 11:26, David Nadlinger wrote: On 2/15/11 10:09 PM, Lars T. Kyllingstad wrote: https://github.com/schacon/libgit That'd rather be http://libgit2.github.com/, though I have no idea how usable it is already. David I've seen that, but hoped for something easier to use. Was hoping

Re: Git library for checkouts?

2011-02-16 Thread Jacob Carlborg
On 2011-02-15 21:32, Jacob Carlborg wrote: Maybe a little off topic but does anyone know about a git library, I'll only need to do checkouts? If it makes any difference I actually meant clone a git repository. -- /Jacob Carlborg

Re: Isn't using find with retro awkward?

2011-02-16 Thread Andrej Mitrovic
On 2/16/11, spir denis.s...@gmail.com wrote: for any reason, I would prefere findBack(haystack, needle); :-) Or maybe find should have an extra parameter that decides if the search begins from the beginning or the end of the range.

Re: Isn't using find with retro awkward?

2011-02-16 Thread Steven Schveighoffer
On Wed, 16 Feb 2011 11:14:27 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 2/16/11, spir denis.s...@gmail.com wrote: for any reason, I would prefere findBack(haystack, needle); :-) Or maybe find should have an extra parameter that decides if the search begins from the

Re: Isn't using find with retro awkward?

2011-02-16 Thread Andrej Mitrovic
Poor implementation, but wouldn't this work?: import std.stdio; import std.range; import std.array; auto findBack(alias pred = a == b, R, E)(R haystack, E needle) if (isBidirectionalRange!R) { R result; size_t index; auto reversed = retro(haystack); foreach (item; reversed)

Re: regex escapes

2011-02-16 Thread Jesse Phillips
spir Wrote: Hello, Which characters are to be escaped: * inside [] classes * outside such classes ? Also, is there for D regexes a free form format (where whitespace can be used to present formats more legibly, but must be escaped as literals)? Though you are probably asking

Re: Isn't using find with retro awkward?

2011-02-16 Thread Andrej Mitrovic
My code is a little bit broken though because if nothing is found the entire range is returned.

Re: Isn't using find with retro awkward?

2011-02-16 Thread Andrej Mitrovic
Quick fix: import std.stdio; import std.range; import std.array; auto findBack(alias pred = a == b, R, E)(R haystack, E needle) if (isBidirectionalRange!R) { R result; size_t index; auto reversed = retro(haystack); bool found; foreach (item; reversed) {

Re: class invariants and property declarations

2011-02-16 Thread Jesse Phillips
Dmitry Olshansky Wrote: Now to properties, this is actually shouldn't be allowed: @property int hours; @property is a annotation applied to functions (getter/setter), to allow calling it with omitted () and a natural assign syntax like this: Why shouldn't it be allowed? While it

Re: class invariants and property declarations

2011-02-16 Thread Dmitry Olshansky
On 16.02.2011 20:47, Jesse Phillips wrote: Dmitry Olshansky Wrote: Now to properties, this is actually shouldn't be allowed: @property int hours; @property is a annotation applied to functions (getter/setter), to allow calling it with omitted () and a natural assign syntax like this:

Re: Isn't using find with retro awkward?

2011-02-16 Thread Steven Schveighoffer
On Wed, 16 Feb 2011 12:37:04 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Quick fix: import std.stdio; import std.range; import std.array; auto findBack(alias pred = a == b, R, E)(R haystack, E needle) if (isBidirectionalRange!R) { R result; size_t index; auto

Re: Defult stack size on Windows?

2011-02-16 Thread Simon
On 15/02/2011 18:22, Simon wrote: On 14/02/2011 22:47, Nick Sabalausky wrote: Anyone know what DMD/OPTLINK's default stack size on windows is? Or how to find out? Dunno. Actually if you have visual studio installed you can use the dumpbin utility. the /headers switch prints out the initial

Re: Isn't using find with retro awkward?

2011-02-16 Thread spir
On 02/16/2011 05:14 PM, Andrej Mitrovic wrote: On 2/16/11, spirdenis.s...@gmail.com wrote: for any reason, I would prefere findBack(haystack, needle); :-) Or maybe find should have an extra parameter that decides if the search begins from the beginning or the end of the range. Yes,

Re: Isn't using find with retro awkward?

2011-02-16 Thread spir
On 02/16/2011 05:24 PM, Steven Schveighoffer wrote: On Wed, 16 Feb 2011 11:14:27 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 2/16/11, spir denis.s...@gmail.com wrote: for any reason, I would prefere findBack(haystack, needle); :-) Or maybe find should have an extra

Re: Isn't using find with retro awkward?

2011-02-16 Thread spir
On 02/16/2011 06:22 PM, Andrej Mitrovic wrote: Poor implementation, but wouldn't this work?: import std.stdio; import std.range; import std.array; auto findBack(alias pred = a == b, R, E)(R haystack, E needle) if (isBidirectionalRange!R) { R result; size_t index; auto

Re: class invariants and property declarations

2011-02-16 Thread Jonathan M Davis
On Wednesday, February 16, 2011 09:47:32 Jesse Phillips wrote: Dmitry Olshansky Wrote: Now to properties, this is actually shouldn't be allowed: @property int hours; @property is a annotation applied to functions (getter/setter), to allow calling it with omitted () and a natural

Re: Isn't using find with retro awkward?

2011-02-16 Thread Steven Schveighoffer
On Wed, 16 Feb 2011 13:43:57 -0500, spir denis.s...@gmail.com wrote: On 02/16/2011 05:24 PM, Steven Schveighoffer wrote: On Wed, 16 Feb 2011 11:14:27 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 2/16/11, spir denis.s...@gmail.com wrote: for any reason, I would prefere

Re: class invariants and property declarations

2011-02-16 Thread Steven Schveighoffer
On Wed, 16 Feb 2011 12:47:32 -0500, Jesse Phillips jessekphillip...@gmail.com wrote: Dmitry Olshansky Wrote: Now to properties, this is actually shouldn't be allowed: @property int hours; @property is a annotation applied to functions (getter/setter), to allow calling it with omitted

Re: Isn't using find with retro awkward?

2011-02-16 Thread Andrej Mitrovic
The only thing I could come up with is exhausting the entire range to get the length of a bidirectional range. But that's inefficient. Anyway here's the dull thing: import std.stdio; import std.range; import std.array; R findBack(alias pred = a == b, R, E)(R haystack, E needle) if

Re: Isn't using find with retro awkward?

2011-02-16 Thread Steven Schveighoffer
On Wed, 16 Feb 2011 14:24:36 -0500, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: The only thing I could come up with is exhausting the entire range to get the length of a bidirectional range. But that's inefficient. Anyway here's the dull thing: import std.stdio; import std.range;

Phobos roadmap?

2011-02-16 Thread simendsjo
I've seen discussions on buffered ranges, std.parallelism, replacement of std.xml, std.process and std.stream and probably several other things I've already forgotten. DMD seems to have a quite updated roadmap in the wiki: http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel#Roadmap Does

Re: Isn't using find with retro awkward?

2011-02-16 Thread jam
On Wed, 16 Feb 2011 20:24:36 +0100, Andrej Mitrovic wrote: The only thing I could come up with is exhausting the entire range to get the length of a bidirectional range. But that's inefficient. Anyway here's the dull thing: import std.stdio; import std.range; import std.array; R

Re: Isn't using find with retro awkward?

2011-02-16 Thread Andrej Mitrovic
On 2/16/11, jam gr0v3e...@gmail.com wrote: void main() { auto a = [5,1,2,3,4,5,1]; auto index = countUntil(retro(a),5); writeln(a[a.length-1-index .. a.length]); } That works for random-access ranges. But I was under the impression that bidirectional ranges don't necessarily

Re: Isn't using find with retro awkward?

2011-02-16 Thread Jonathan M Davis
On Wednesday, February 16, 2011 13:00:13 Andrej Mitrovic wrote: On 2/16/11, jam gr0v3e...@gmail.com wrote: void main() { auto a = [5,1,2,3,4,5,1]; auto index = countUntil(retro(a),5); writeln(a[a.length-1-index .. a.length]); } That works for random-access ranges.

Re: Phobos roadmap?

2011-02-16 Thread Jonathan M Davis
On Wednesday, February 16, 2011 12:13:59 simendsjo wrote: I've seen discussions on buffered ranges, std.parallelism, replacement of std.xml, std.process and std.stream and probably several other things I've already forgotten. DMD seems to have a quite updated roadmap in the wiki:

Re: Isn't using find with retro awkward?

2011-02-16 Thread Jonathan M Davis
On Wednesday, February 16, 2011 13:36:54 Jonathan M Davis wrote: On Wednesday, February 16, 2011 13:00:13 Andrej Mitrovic wrote: On 2/16/11, jam gr0v3e...@gmail.com wrote: void main() { auto a = [5,1,2,3,4,5,1]; auto index = countUntil(retro(a),5);

Re: Isn't using find with retro awkward?

2011-02-16 Thread spir
On 02/16/2011 09:42 PM, jam wrote: On Wed, 16 Feb 2011 20:24:36 +0100, Andrej Mitrovic wrote: The only thing I could come up with is exhausting the entire range to get the length of a bidirectional range. But that's inefficient. Anyway here's the dull thing: import std.stdio; import

Re: Isn't using find with retro awkward?

2011-02-16 Thread jam
On Wed, 16 Feb 2011 22:00:13 +0100, Andrej Mitrovic wrote: On 2/16/11, jam gr0v3e...@gmail.com wrote: void main() { auto a = [5,1,2,3,4,5,1]; auto index = countUntil(retro(a),5); writeln(a[a.length-1-index .. a.length]); } That works for random-access ranges. But I was

Re: Isn't using find with retro awkward?

2011-02-16 Thread Andrej Mitrovic
On 2/16/11, jam gr0v3e...@gmail.com wrote: import std.stdio,std.algorithm,std.range,std.container; void main() { auto a = [5,1,2,3,4,5,1]; auto index = countUntil(retro(a),5); auto R = retro(take(retro(a),index+1)); writeln(R); R[0] = 6; writeln(a); } but this

Re: Isn't using find with retro awkward?

2011-02-16 Thread jam
On Thu, 17 Feb 2011 00:05:15 +0100, Andrej Mitrovic wrote: On 2/16/11, jam gr0v3e...@gmail.com wrote: import std.stdio,std.algorithm,std.range,std.container; void main() { auto a = [5,1,2,3,4,5,1]; auto index = countUntil(retro(a),5); auto R = retro(take(retro(a),index+1));

Re: Isn't using find with retro awkward?

2011-02-16 Thread Jonathan M Davis
On Wednesday, February 16, 2011 15:19:01 jam wrote: On Thu, 17 Feb 2011 00:05:15 +0100, Andrej Mitrovic wrote: On 2/16/11, jam gr0v3e...@gmail.com wrote: import std.stdio,std.algorithm,std.range,std.container; void main() { auto a = [5,1,2,3,4,5,1]; auto index =

Re: Double-dispatch

2011-02-16 Thread Peter Alexander
On 13/02/11 9:32 PM, Sean Eskapp wrote: == Quote from bearophile (bearophileh...@lycos.com)'s article Sean Eskapp: Is there a nicer way to do this in D, or am I stuck with the same thing? Andrei has recently said no one needs double dispatch (in D) :-) So Andrei will be interested in your