Re: DbC bug?

2012-02-27 Thread Magnus Lie Hetland
On 2012-02-23 15:59:18 +, H. S. Teoh said: Looks like a compiler bug. You should never be able to access invalid values. Indeed. After spending quite a while whittling down my code, I've posted the following snippet as issue #7599: module main; import std.conv; class Class { void

Re: SONAME and D

2012-02-27 Thread Jacob Carlborg
On 2012-02-26 14:53, bioinfornatics wrote: Le vendredi 24 février 2012 à 15:56 +0100, Mike Wey a écrit : On 02/23/2012 08:29 PM, bioinfornatics wrote: Le jeudi 23 février 2012 à 19:46 +0100, Mike Wey a écrit : On 02/23/2012 05:27 PM, bioinfornatics wrote: dear, for set soname with: - gdc:

Re: Make alias parameter optional?

2012-02-27 Thread Jacob Carlborg
On 2012-02-27 00:04, Ali Çehreli wrote: On 02/26/2012 03:45 AM, Jacob Carlborg wrote: On 2012-02-26 11:03, Ali Çehreli wrote: On 02/25/2012 05:04 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 23:10:51 UTC, Ary Manzana wrote: On 2/25/12 7:31 PM, Robert Rouse wrote: ...

Re: SONAME and D

2012-02-27 Thread bioinfornatics
Le lundi 27 février 2012 à 09:51 +0100, Jacob Carlborg a écrit : On 2012-02-26 14:53, bioinfornatics wrote: Le vendredi 24 février 2012 à 15:56 +0100, Mike Wey a écrit : On 02/23/2012 08:29 PM, bioinfornatics wrote: Le jeudi 23 février 2012 à 19:46 +0100, Mike Wey a écrit : On 02/23/2012

Re: SONAME and D

2012-02-27 Thread Mike Wey
On 02/27/2012 10:30 AM, bioinfornatics wrote: Le lundi 27 février 2012 à 09:51 +0100, Jacob Carlborg a écrit : On 2012-02-26 14:53, bioinfornatics wrote: Le vendredi 24 février 2012 à 15:56 +0100, Mike Wey a écrit : On 02/23/2012 08:29 PM, bioinfornatics wrote: Le jeudi 23 février 2012 à

Re: SONAME and D

2012-02-27 Thread bioinfornatics
Le lundi 27 février 2012 à 11:36 +0100, Mike Wey a écrit : On 02/27/2012 10:30 AM, bioinfornatics wrote: Le lundi 27 février 2012 à 09:51 +0100, Jacob Carlborg a écrit : On 2012-02-26 14:53, bioinfornatics wrote: Le vendredi 24 février 2012 à 15:56 +0100, Mike Wey a écrit : On 02/23/2012

Re: Make alias parameter optional?

2012-02-27 Thread Ary Manzana
On 2/25/12 10:04 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 23:10:51 UTC, Ary Manzana wrote: On 2/25/12 7:31 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 22:12:55 UTC, Ali Çehreli wrote: On 02/25/2012 01:55 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at

Re: Re: class templates and static if

2012-02-27 Thread Tyler Jameson Little
Parser!(Type.request) h = new Parser!(Type.request)(Hello world) Wow, I was so close! I had tried this: Parser!Type.request h = new Parser!Type.request(Hello world); but that didn't work. I didn't think about enclosing it in parens! I didn't want to do subclassing, because my parser is a

Re: Re: class templates and static if

2012-02-27 Thread H. S. Teoh
On Mon, Feb 27, 2012 at 09:29:25AM -0700, Tyler Jameson Little wrote: Parser!(Type.request) h = new Parser!(Type.request)(Hello world) Even better: auto h = new Parser!(Type.request)(Hello world); T -- First Rule of History: History doesn't repeat itself -- historians merely repeat

Re: Re: class templates and static if

2012-02-27 Thread Andrej Mitrovic
On 2/27/12, Tyler Jameson Little beatgam...@gmail.com wrote: That's why I thought this model would be so cool, because I could remove conditions from the generated code, and get rid of a lot of the conditionals. I think Nick Sabalausky talks about this concept (removing conditionals via

Binary I/O for Newbie

2012-02-27 Thread tjb
All, I am just starting to learn D. I am an economist - not a programmer, so I appreciate your patience with lack of knowledge. I have some financial data in a binary file that I would like to process. In C++ I have the data in a structure like this: struct TaqIdx { char symbol[10];

Re: Binary I/O for Newbie

2012-02-27 Thread Robert Jacques
On Mon, 27 Feb 2012 12:21:21 -0600, tjb broug...@gmail.com wrote: All, I am just starting to learn D. I am an economist - not a programmer, so I appreciate your patience with lack of knowledge. I have some financial data in a binary file that I would like to process. In C++ I have the

Re: Binary I/O for Newbie

2012-02-27 Thread Justin Whear
On Mon, 27 Feb 2012 19:21:21 +0100, tjb wrote: All, I am just starting to learn D. I am an economist - not a programmer, so I appreciate your patience with lack of knowledge. I have some financial data in a binary file that I would like to process. In C++ I have the data in a structure

Re: Binary I/O for Newbie

2012-02-27 Thread Ali Çehreli
On 02/27/2012 10:21 AM, tjb wrote: I have some financial data in a binary file that I would like to process. In C++ I have the data in a structure like this: struct TaqIdx { char symbol[10]; int tdate; int begrec; int endrec; } The equivalent of that C++ (and C) struct would be almost

Re: Binary I/O for Newbie

2012-02-27 Thread Tobias Brandt
Doesn't the struct alignment play a role here?

Re: class templates and static if

2012-02-27 Thread Ali Çehreli
On 02/27/2012 08:29 AM, Tyler Jameson Little wrote: I didn't want to do subclassing, because my parser is a state-machine style parser, so it's in a big switch. Pretty gross, but I would like it to be as fast as possible. That's why I thought this model would be so cool, because I could

Re: Binary I/O for Newbie

2012-02-27 Thread Justin Whear
On Mon, 27 Feb 2012 19:42:36 +0100, Tobias Brandt wrote: Doesn't the struct alignment play a role here? Good point. If the data is packed, you can toss an align(1) on the front of the struct declaration.

Re: class templates and static if

2012-02-27 Thread Jonathan M Davis
On Monday, February 27, 2012 10:55:12 Ali Çehreli wrote: On 02/27/2012 08:29 AM, Tyler Jameson Little wrote: I didn't want to do subclassing, because my parser is a state-machine style parser, so it's in a big switch. Pretty gross, but I would like it to be as fast as possible.

Re: Binary I/O for Newbie

2012-02-27 Thread tjb
On Monday, 27 February 2012 at 18:56:15 UTC, Justin Whear wrote: On Mon, 27 Feb 2012 19:42:36 +0100, Tobias Brandt wrote: Doesn't the struct alignment play a role here? Good point. If the data is packed, you can toss an align(1) on the front of the struct declaration. So, something like

Re: Binary I/O for Newbie

2012-02-27 Thread Tobias Brandt
So, something like this should work: [...] It really depends on how you wrote the file originally. If you know that it is packed, i.e. 10+32+32+32=106 bytes per record, then yes. If you wrote to the file with a C++ program, then I guess the compiler aligned the data so that the whole struct is

Re: Make alias parameter optional?

2012-02-27 Thread Robert Rouse
On Monday, 27 February 2012 at 14:57:56 UTC, Ary Manzana wrote: On 2/25/12 10:04 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 23:10:51 UTC, Ary Manzana wrote: On 2/25/12 7:31 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 22:12:55 UTC, Ali Çehreli wrote: On

Re: Binary I/O for Newbie

2012-02-27 Thread Ali Çehreli
On 02/27/2012 11:27 AM, Tobias Brandt wrote: So, something like this should work: [...] It really depends on how you wrote the file originally. If you know that it is packed, i.e. 10+32+32+32=106 bytes per record, then yes. You meant 4 bytes per int. :) If you wrote to the file with a

Re: Binary I/O for Newbie

2012-02-27 Thread Tobias Brandt
It really depends on how you wrote the file originally. If you know that it is packed, i.e. 10+32+32+32=106 bytes per record, then yes. You meant 4 bytes per int. :) Yep, good catch. If you wrote to the file with a C++ program, then I guess the compiler aligned the data so that the whole

Re: Binary I/O for Newbie

2012-02-27 Thread Ali Çehreli
On 02/27/2012 11:43 AM, Tobias Brandt wrote: If you wrote to the file with a C++ program, then I guess the compiler aligned the data so that the whole struct is 128 bytes in size. Technically, the C++ compiler is allowed to do anything short of changing the order of the struct fields. That

Re: class templates and static if

2012-02-27 Thread Dmitry Olshansky
On 27.02.2012 23:18, Jonathan M Davis wrote: On Monday, February 27, 2012 10:55:12 Ali Çehreli wrote: On 02/27/2012 08:29 AM, Tyler Jameson Little wrote: I didn't want to do subclassing, because my parser is a state-machine style parser, so it's in a big switch. Pretty gross, but I would

Re: Binary I/O for Newbie

2012-02-27 Thread tjb
On Monday, 27 February 2012 at 19:28:07 UTC, Tobias Brandt wrote: So, something like this should work: [...] It really depends on how you wrote the file originally. If you know that it is packed, i.e. 10+32+32+32=106 bytes per record, then yes. If you wrote to the file with a C++ program,

Re: Binary I/O for Newbie

2012-02-27 Thread Tobias Brandt
Just looked at my old C++ code.  And the struct looks like this: struct TaqIdx {  char symbol[10];  int tdate;  int begrec;  int endrec; }__attribute__((packed)); So I am guessing I want to use the align(1) as Justin suggested. Correct? Yes.

Is empty array null?

2012-02-27 Thread Pedro Lacerda
The expression [] is null evaluates to true here using 2.058, but I expected to be false. What am I missing? Pedro Lacerda

Re: Is empty array null?

2012-02-27 Thread Pedro Lacerda
Ouch, I just found http://d.puremagic.com/issues/show_bug.cgi?id=3889 So how would I differ from an empty array and a null value? Pedro Lacerda 2012/2/27 Pedro Lacerda pslace...@gmail.com The expression [] is null evaluates to true here using 2.058, but I expected to be false. What am I

Re: Is empty array null?

2012-02-27 Thread Justin Whear
On Mon, 27 Feb 2012 17:44:40 -0300, Pedro Lacerda wrote: The expression [] is null evaluates to true here using 2.058, but I expected to be false. What am I missing? Pedro Lacerda divThe expression quot;[] is nullquot; evaluates to true here using 2.058, but I expected to be false. What am

Re: Is empty array null?

2012-02-27 Thread Ellery Newcomer
On 02/27/2012 03:12 PM, Pedro Lacerda wrote: Ouch, I just found http://d.puremagic.com/issues/show_bug.cgi?id=3889 So how would I differ from an empty array and a null value? Pedro Lacerda If you know your type is an array, just use a.length to test if the array is empty. The concept of

Re: Is empty array null?

2012-02-27 Thread Ali Çehreli
On 02/27/2012 01:17 PM, Justin Whear wrote: On Mon, 27 Feb 2012 17:44:40 -0300, Pedro Lacerda wrote: The expression [] is null evaluates to true here using 2.058, but I expected to be false. What am I missing? Pedro Lacerda divThe expressionquot;[] is nullquot; evaluates to true here using

Re: Is empty array null?

2012-02-27 Thread Ellery Newcomer
On 02/27/2012 03:17 PM, Justin Whear wrote: null makes sense to me. If the length is null, where can the ptr member point to other than null? In the case of empty array slices, ptr can point to anywhere. But then, empty array slices aren't null.

Re: Is empty array null?

2012-02-27 Thread Jonathan M Davis
On Monday, February 27, 2012 17:44:40 Pedro Lacerda wrote: The expression [] is null evaluates to true here using 2.058, but I expected to be false. What am I missing? Arrays treat null kind of funny. For equality, null is considered to be the same as an array with length 0. So, int[] a;

Re: class templates and static if

2012-02-27 Thread Jonathan M Davis
On Monday, February 27, 2012 23:55:39 Dmitry Olshansky wrote: On 27.02.2012 23:18, Jonathan M Davis wrote: On Monday, February 27, 2012 10:55:12 Ali Çehreli wrote: On 02/27/2012 08:29 AM, Tyler Jameson Little wrote: I didn't want to do subclassing, because my parser is a state-machine

Re: class templates and static if

2012-02-27 Thread Ali Çehreli
On 02/27/2012 02:06 PM, Jonathan M Davis wrote: I'm not saying that dmd doesn't ever optimize switch statements. I'm just saying that as I understand it, it doesn't always do so (its performance with ranged case statements isn't great for instance). Odds are that it _does_ optimize

Re: Make alias parameter optional?

2012-02-27 Thread David Nadlinger
On Monday, 27 February 2012 at 19:34:45 UTC, Robert Rouse wrote: Which thing? Delegates can already access variables outside, because that's what they are for. The »returning from block returns from outer function« part. Also applies to similar control statements. David

Re: Using delegates in callbacks for extern(C) functions

2012-02-27 Thread Ali Çehreli
On 02/25/2012 08:12 AM, Timon Gehr wrote: On 02/24/2012 07:22 PM, simendsjo wrote: I have a C function taking a callback function as a parameter. My thought was to wrap this up using a template, but I cannot get it to work: extern(C) alias void function() Callback; template Wrap(alias dg)

Re: Using delegates in callbacks for extern(C) functions

2012-02-27 Thread Jonathan M Davis
On Monday, February 27, 2012 16:42:06 Ali Çehreli wrote: On 02/25/2012 08:12 AM, Timon Gehr wrote: On 02/24/2012 07:22 PM, simendsjo wrote: I have a C function taking a callback function as a parameter. My thought was to wrap this up using a template, but I cannot get it to work:

Re: Is empty array null?

2012-02-27 Thread Pedro Lacerda
So are a newly allocated array and a null one just the same thing? int[] a = [], b = null; assert(a == b); assert(a.length == b.length); assert(a.ptr == a.ptr); My code made distinction between empty and invalid collections, this mean that need to track the invalidation on

Re: Is empty array null?

2012-02-27 Thread Jonathan M Davis
On Monday, February 27, 2012 22:45:06 Pedro Lacerda wrote: So are a newly allocated array and a null one just the same thing? int[] a = [], b = null; assert(a == b); assert(a.length == b.length); assert(a.ptr == a.ptr); My code made distinction between empty and invalid collections, this

Re: Write struct to file

2012-02-27 Thread Chopin
Ah, I get it now. Thank you so much! I think I will go for JSON. It will be mostly string data anyway :)!

Reflection

2012-02-27 Thread Joshua Niehus
Hello, I dont understand the following snippet's output: import std.stdio, std.traits; void main() { writeln(isSomeFunction!(writeln)); writeln(isCallable!(writeln)); writeln(Yes I am...); } /* OUTPUT */ false false Yes I am... If 'writeln' isn't a method/function and it's not

Re: Reflection

2012-02-27 Thread Jesse Phillips
On Tuesday, 28 February 2012 at 05:56:12 UTC, Joshua Niehus wrote: Hello, I dont understand the following snippet's output: import std.stdio, std.traits; void main() { writeln(isSomeFunction!(writeln)); writeln(isCallable!(writeln)); writeln(Yes I am...); } /* OUTPUT */ false

Re: Reflection

2012-02-27 Thread Puming
It is a template. Is a template callable? So what's the isCallable and isSomeFunction equivalent for templates?

Re: Reflection

2012-02-27 Thread Joshua Niehus
On Tuesday, 28 February 2012 at 06:10:11 UTC, Jesse Phillips wrote: It is a template. I see, thanks. And I bet its not possible to figure out if a template is a function template or a class template etc...

Re: Reflection

2012-02-27 Thread James Miller
On 28 February 2012 19:27, Joshua Niehus jm.nie...@gmail.com wrote: On Tuesday, 28 February 2012 at 06:10:11 UTC, Jesse Phillips wrote: It is a template. I see, thanks. And I bet its not possible to figure out if a template is a function template or a class template etc... Not really,

Re: Reflection

2012-02-27 Thread Jesse Phillips
On Tuesday, 28 February 2012 at 06:26:38 UTC, Puming wrote: It is a template. Is a template callable? So what's the isCallable and isSomeFunction equivalent for templates? I suppose it could be considered a bug as it is mostly a syntactic request/check. I'd expect