Proper Use of Assert and Enforce

2012-03-13 Thread Chris Pons
I'm new, and trying to incorporate assert and enforce into my program properly. My question revolves around, the fact that assert is only evaluated when using the debug switch. I read that assert throws a more serious exception than enforce does, is this correct? I'm trying to use enforce in

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Andrej Mitrovic
On 3/14/12, Alex Rønne Petersen wrote: > void foo(S s) // compiler decides to pass by ref > { > s = S(2); > } Well in this case it wouldn't pass by ref since it sees an assignment. But I can see how this would become tricky business (e.g. "why is my code slow all of a sudden"). const ref has

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Jonathan M Davis
On Wednesday, March 14, 2012 01:36:40 Alex Rønne Petersen wrote: > On 14-03-2012 01:18, Jonathan M Davis wrote: > > On Wednesday, March 14, 2012 01:14:04 Alex Rønne Petersen wrote: > >> On 14-03-2012 01:10, Jonathan M Davis wrote: > >>> On Tuesday, March 13, 2012 22:03:45 Alex Rønne Petersen wrote:

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Jonathan M Davis
On Wednesday, March 14, 2012 01:43:54 Andrej Mitrovic wrote: > On 3/14/12, Jonathan M Davis wrote: > > As I understand it, auto ref is supposed to work with _any_ function. The > > _compiler_ decides whether it's best to use a ref or a value. > > I never really understood the need for 'const ref'

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 14-03-2012 01:43, Andrej Mitrovic wrote: On 3/14/12, Jonathan M Davis wrote: As I understand it, auto ref is supposed to work with _any_ function. The _compiler_ decides whether it's best to use a ref or a value. I never really understood the need for 'const ref' with structures. If the co

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Andrej Mitrovic
On 3/14/12, Jonathan M Davis wrote: > As I understand it, auto ref is supposed to work with _any_ function. The > _compiler_ decides whether it's best to use a ref or a value. I never really understood the need for 'const ref' with structures. If the compiler knows the size of a structure shouldn

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 14-03-2012 01:18, Jonathan M Davis wrote: On Wednesday, March 14, 2012 01:14:04 Alex Rønne Petersen wrote: On 14-03-2012 01:10, Jonathan M Davis wrote: On Tuesday, March 13, 2012 22:03:45 Alex Rønne Petersen wrote: Did you see my other post? Maybe we could do something like this: equals_t

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread Chris Pons
Oops, I didn't see the replies, after my last message. I'll check this out. Thanks! On Tuesday, 13 March 2012 at 20:34:54 UTC, Kiith-Sa wrote: SciD is a scientific math library providing vectors/matrices of arbitrary sizes, but not useful at all for game development. See gl3n for a game-orient

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Jonathan M Davis
On Wednesday, March 14, 2012 01:14:04 Alex Rønne Petersen wrote: > On 14-03-2012 01:10, Jonathan M Davis wrote: > > On Tuesday, March 13, 2012 22:03:45 Alex Rønne Petersen wrote: > >> Did you see my other post? Maybe we could do something like this: > >> > >> equals_t opEquals()(const auto ref Sys

Re: Simple operator precidence chart (and associativity)?

2012-03-13 Thread Nick Sabalausky
"Timon Gehr" wrote in message news:jjokc7$t3j$1...@digitalmars.com... > On 03/13/2012 11:29 PM, Nick Sabalausky wrote: >> I'm reading through D's grammar spec, and maybe it's just not enough >> sleep >> or some such, but my brain is turning to mud: >> >> Is there a simple operator precidence cha

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread bearophile
Alex R. Petersen: > Most compilers implement booleans as native integers and narrow/expand > them when storing/loading to/from memory, so it's unlikely to matter at all. If you have the int value 25, this is a true value, in C you are free to use it for its zero/nonzero quality. But if opEquals

Re: Simple operator precidence chart (and associativity)?

2012-03-13 Thread Jonathan M Davis
On Tuesday, March 13, 2012 18:29:03 Nick Sabalausky wrote: > I'm reading through D's grammar spec, and maybe it's just not enough sleep > or some such, but my brain is turning to mud: > > Is there a simple operator precidence chart somewhere? (Also, for > associativity: Assign and OpAssign are rig

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 14-03-2012 01:10, Jonathan M Davis wrote: On Tuesday, March 13, 2012 22:03:45 Alex Rønne Petersen wrote: Did you see my other post? Maybe we could do something like this: equals_t opEquals()(const auto ref SysTime rhs) const pure nothrow That would probably work (though I wouldn't use equa

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Jonathan M Davis
On Tuesday, March 13, 2012 22:03:45 Alex Rønne Petersen wrote: > Did you see my other post? Maybe we could do something like this: > > equals_t opEquals()(const auto ref SysTime rhs) const pure nothrow That would probably work (though I wouldn't use equals_t, since it seems like an utterly point

Re: Simple operator precidence chart (and associativity)?

2012-03-13 Thread Timon Gehr
On 03/13/2012 11:29 PM, Nick Sabalausky wrote: I'm reading through D's grammar spec, and maybe it's just not enough sleep or some such, but my brain is turning to mud: Is there a simple operator precidence chart somewhere? I don't think there is, but I think I can create one: !

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 13-03-2012 23:35, bearophile wrote: Alex R. Petersen: It was an integer in the past (believe it or not). :) equals_t made the transition easier. Thank you for your answers, now I understand. Using an int makes sense for opEquals, because if opEquals doesn't get inlined then using int is s

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread bearophile
Alex R. Petersen: > It was an integer in the past (believe it or not). :) equals_t made the > transition easier. Thank you for your answers, now I understand. Using an int makes sense for opEquals, because if opEquals doesn't get inlined then using int is sometimes able to give you a bit more e

Simple operator precidence chart (and associativity)?

2012-03-13 Thread Nick Sabalausky
I'm reading through D's grammar spec, and maybe it's just not enough sleep or some such, but my brain is turning to mud: Is there a simple operator precidence chart somewhere? (Also, for associativity: Assign and OpAssign are right-associative and everything else is left-associative, correct?)

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 13-03-2012 22:08, H. S. Teoh wrote: On Tue, Mar 13, 2012 at 10:02:19PM +0100, Alex Rønne Petersen wrote: On 13-03-2012 21:39, bearophile wrote: Alex R. Petersen: (Stylistic note: use equals_t instead of bool.) What is equals_t? See it's used here: http://dlang.org/phobos/object.html Bye

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread Chris Pons
SciD looks nice, but it seems to be a bit too complicated for my use. Are there any other alternatives? On Tuesday, 13 March 2012 at 20:14:14 UTC, Chris Pons wrote: Thanks, I'll take a look. I'm new, so I might need some help properly building this. I will post back if I have any problems. O

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread H. S. Teoh
On Tue, Mar 13, 2012 at 10:02:19PM +0100, Alex Rønne Petersen wrote: > On 13-03-2012 21:39, bearophile wrote: > >Alex R. Petersen: > > > >>(Stylistic note: use equals_t instead of bool.) > > > >What is equals_t? > >See it's used here: > >http://dlang.org/phobos/object.html > > > >Bye, > >bearophile

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 13-03-2012 21:55, Jonathan M Davis wrote: On Tuesday, March 13, 2012 19:28:26 Johannes Pfau wrote: My std.uuid module doesn't compile with the latest dmd. I guess it's because of a wrong opEquals signature, this is what I have now: -- @safe pure nothrow bool opEquals(ref const UUID s

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 13-03-2012 21:39, bearophile wrote: Alex R. Petersen: (Stylistic note: use equals_t instead of bool.) What is equals_t? See it's used here: http://dlang.org/phobos/object.html Bye, bearophile It's just aliased to bool right now. -- - Alex

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread sclytrack
Stride(T) row() { } Stride!(T) row() { }

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Jonathan M Davis
On Tuesday, March 13, 2012 19:28:26 Johannes Pfau wrote: > My std.uuid module doesn't compile with the latest dmd. I guess it's > because of a wrong opEquals signature, this is what I have now: > > -- > @safe pure nothrow bool opEquals(ref const UUID s) const > { > return s.data == this.da

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread sclytrack
On 03/13/2012 09:30 PM, sclytrack wrote: On 03/13/2012 09:06 PM, Dmitry Olshansky wrote: On 14.03.2012 0:03, H. S. Teoh wrote: On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote: Does D have a math library that defines, points, vectors and matrices including the appropriate functions(a

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread bearophile
Alex R. Petersen: > (Stylistic note: use equals_t instead of bool.) What is equals_t? See it's used here: http://dlang.org/phobos/object.html Bye, bearophile

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread Kiith-Sa
SciD is a scientific math library providing vectors/matrices of arbitrary sizes, but not useful at all for game development. See gl3n for a game-oriented vector/matrix library: https://bitbucket.org/dav1d/gl3n Also, AFAIK, Manu is working on what should end up being a Phobos module for game-ori

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread sclytrack
On 03/13/2012 09:06 PM, Dmitry Olshansky wrote: On 14.03.2012 0:03, H. S. Teoh wrote: On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote: Does D have a math library that defines, points, vectors and matrices including the appropriate functions(addition, dot product, cross product, etc)?

Does synchronized support recursive locking?

2012-03-13 Thread Alex Rønne Petersen
What the title says. It seems that core.sync.mutex does, but not sure about the synchronized statement. -- - Alex

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread Chris Pons
Thanks, I'll take a look. I'm new, so I might need some help properly building this. I will post back if I have any problems. On Tuesday, 13 March 2012 at 20:06:13 UTC, Dmitry Olshansky wrote: On 14.03.2012 0:03, H. S. Teoh wrote: On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote: Do

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread Dmitry Olshansky
On 14.03.2012 0:03, H. S. Teoh wrote: On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote: Does D have a math library that defines, points, vectors and matrices including the appropriate functions(addition, dot product, cross product, etc)? I'd like to know too. I have a medium-sized D

Re: Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread H. S. Teoh
On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote: > Does D have a math library that defines, points, vectors and > matrices including the appropriate functions(addition, dot product, > cross product, etc)? I'd like to know too. I have a medium-sized D project in the works, but right now

Re: Can I do an or in a version block?

2012-03-13 Thread H. S. Teoh
On Tue, Mar 13, 2012 at 11:28:24AM -0700, Ali Çehreli wrote: [...] > We are getting a little off topic here but I've been following the > recent unit test thread about writing to files. Unit tests should not > have external interactions like that either. For example, no test > should connect to an

Math Libraries (and vectors, matrices, etc)

2012-03-13 Thread Chris Pons
Does D have a math library that defines, points, vectors and matrices including the appropriate functions(addition, dot product, cross product, etc)? I'm starting my next game and I would like to know what my options are. I plan on using SDL, I'm not exactly into OpenGL yet, since I'm new and

Re: Can I do an or in a version block?

2012-03-13 Thread Ali Çehreli
On 03/13/2012 11:49 AM, Andrej Mitrovic wrote: On 3/13/12, Ali Çehreli wrote: Developers wouldn't want that to happen every time a .d file is compiled. Well luckily unittests don't run when you compile a .d file but when you run the app! :) Good point. :) Our C++ unit tests are a part of a

Re: toUTFz again

2012-03-13 Thread Jonathan M Davis
On Tuesday, March 13, 2012 19:13:06 Andrej Mitrovic wrote: > On 3/13/12, Andrej Mitrovic wrote: > > I've completely lost track of what happened with the whole toUTF16z > > story > > Btw, to!string still doesn't work with wchar* arguments. I currently > use this hack: > > wstring fromUTF16z(in wc

Re: Can I do an or in a version block?

2012-03-13 Thread Jonathan M Davis
On Tuesday, March 13, 2012 15:04:09 Ary Manzana wrote: > How can you re-run just a failing test? (without having to run all the > previous tests that will succeed?) You can't, not without essentially creating your own unit testing framework. D's unit testing framework is quite simple. If you comp

Re: Can I do an or in a version block?

2012-03-13 Thread Andrej Mitrovic
On 3/13/12, Ali Çehreli wrote: > Developers wouldn't > want that to happen every time a .d file is compiled. Well luckily unittests don't run when you compile a .d file but when you run the app! :)

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 13-03-2012 19:43, Jesse Phillips wrote: On Tuesday, 13 March 2012 at 18:28:27 UTC, Johannes Pfau wrote: My std.uuid module doesn't compile with the latest dmd. I guess it's because of a wrong opEquals signature, this is what I have now: -- @safe pure nothrow bool opEquals(ref const U

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Jesse Phillips
On Tuesday, 13 March 2012 at 18:28:27 UTC, Johannes Pfau wrote: My std.uuid module doesn't compile with the latest dmd. I guess it's because of a wrong opEquals signature, this is what I have now: -- @safe pure nothrow bool opEquals(ref const UUID s) const { return s.data == this.da

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Alex Rønne Petersen
On 13-03-2012 19:28, Johannes Pfau wrote: My std.uuid module doesn't compile with the latest dmd. I guess it's because of a wrong opEquals signature, this is what I have now: -- @safe pure nothrow bool opEquals(ref const UUID s) const { return s.data == this.data; } -- and

Re: What's the correct opEquals signature for structs?

2012-03-13 Thread Johannes Pfau
Am Tue, 13 Mar 2012 19:28:26 +0100 schrieb Johannes Pfau : > My std.uuid module doesn't compile with the latest dmd. I guess it's > because of a wrong opEquals signature, this is what I have now: > > -- > @safe pure nothrow bool opEquals(ref const UUID s) const > { > return s.data ==

What's the correct opEquals signature for structs?

2012-03-13 Thread Johannes Pfau
My std.uuid module doesn't compile with the latest dmd. I guess it's because of a wrong opEquals signature, this is what I have now: -- @safe pure nothrow bool opEquals(ref const UUID s) const { return s.data == this.data; } -- and -- assert(UUID("---0

Re: Can I do an or in a version block?

2012-03-13 Thread Ali Çehreli
On 03/13/2012 11:04 AM, Ary Manzana wrote: > On 3/13/12 2:21 PM, Ali Çehreli wrote: >> On 03/09/2012 06:20 AM, Andrej Mitrovic wrote: >> >> > The same story goes for unittests which can't be independently >> > ran to get a list of all failing unittests >> >> D unittest blocks are for code correctn

Re: toUTFz again

2012-03-13 Thread Jonathan M Davis
On Tuesday, March 13, 2012 19:00:29 Andrej Mitrovic wrote: > I've completely lost track of what happened with the whole toUTF16z > story, but anyway since it's in std.utf why doesn't it just forward to > toUTFz? There's a pull request which includes other changes to std.utf which has been sitting

Re: toUTFz again

2012-03-13 Thread Andrej Mitrovic
On 3/13/12, Andrej Mitrovic wrote: > I've completely lost track of what happened with the whole toUTF16z > story Btw, to!string still doesn't work with wchar* arguments. I currently use this hack: wstring fromUTF16z(in wchar* s) { if (s is null) return null; wchar* ptr; for (ptr = ca

Re: Can I do an or in a version block?

2012-03-13 Thread Ary Manzana
On 3/13/12 2:21 PM, Ali Çehreli wrote: On 03/09/2012 06:20 AM, Andrej Mitrovic wrote: > The same story goes for unittests which can't be independently > ran to get a list of all failing unittests D unittest blocks are for code correctness (as opposed to other meanings of the unfortunately ove

toUTFz again

2012-03-13 Thread Andrej Mitrovic
I've completely lost track of what happened with the whole toUTF16z story, but anyway since it's in std.utf why doesn't it just forward to toUTFz? const(wchar)* toUTF16z(T)(T input) if (isSomeString!T) { return toUTFz!(const(wchar)*)(input); } That way it can take any string argument and

Re: Sorting char arrays

2012-03-13 Thread Jonathan M Davis
On Tuesday, March 13, 2012 10:13:23 Magnus Lie Hetland wrote: > On 2012-03-12 17:24:56 +, Jonathan M Davis said: > > The problem is that sort requires a random access range, and narrow string > > (string and wstring) aren't, because they're variable length encoded. I'm > > not sure that strings

Re: Can I do an or in a version block?

2012-03-13 Thread Ali Çehreli
On 03/09/2012 06:20 AM, Andrej Mitrovic wrote: > The same story goes for unittests which can't be independently > ran to get a list of all failing unittests D unittest blocks are for code correctness (as opposed to other meanings of the unfortunately overused term "unit testing" e.g. the functi

Re: problems with DPL example.

2012-03-13 Thread Shripad K
Boy its really hard to navigate this forum for an old thread. Seems like a lot has changed in D since this thread. Here is the correct snippet if someone comes searching for "error: undefined identifier splitter" like me :) (using DMD64 D Compiler v2.058) import std.stdio, std.string, std.algo

Re: Why doesn't this have a length?

2012-03-13 Thread Magnus Lie Hetland
On 2012-03-13 14:24:37 +, H. S. Teoh said: Indeed. Would've thought const AA keys would be reasonable. (In Python they're *required*... :) [...] I'm of the opinion that AA keys should be *implicitly* immutable. Seconded, whole-heartedly. -- Magnus Lie Hetland http://hetland.org

Re: Why doesn't this have a length?

2012-03-13 Thread H. S. Teoh
On Tue, Mar 13, 2012 at 10:02:02AM +0100, Magnus Lie Hetland wrote: > On 2012-03-13 02:27:46 +, Simen Kjærås said: > > >Weird. > > Indeed. Would've thought const AA keys would be reasonable. (In > Python they're *required*... :) [...] I'm of the opinion that AA keys should be *implicitly* im

Re: Sorting char arrays

2012-03-13 Thread Magnus Lie Hetland
On 2012-03-12 17:33:35 +, Ali Çehreli said: You can use isNarrowString to either disallow or provide special implementation for narrow strings (char[] and wchar[]): Ah -- useful, thanks! -- Magnus Lie Hetland http://hetland.org

Re: Sorting char arrays

2012-03-13 Thread Magnus Lie Hetland
On 2012-03-12 17:24:56 +, Jonathan M Davis said: The problem is that sort requires a random access range, and narrow string (string and wstring) aren't, because they're variable length encoded. I'm not sure that strings _can_ be efficiently sorted, because of that, but maybe there's a sortin

Re: Why doesn't this have a length?

2012-03-13 Thread Magnus Lie Hetland
On 2012-03-13 02:27:46 +, Simen Kjærås said: Weird. Indeed. Would've thought const AA keys would be reasonable. (In Python they're *required*... :) You get a different error message from what I get. My reduced code: [snip] http://d.puremagic.com/issues/show_bug.cgi?id=7695 I guess