Re: Should writef try to statically check for format specifiers?

2011-04-11 Thread Andrej Mitrovic
On 4/12/11, Jesse Phillips wrote: > On Tue, 12 Apr 2011 01:55:24 +0200, Andrej Mitrovic wrote: > >> On 4/12/11, Jesse Phillips wrote: >>> Andrej Mitrovic Wrote: >>> %s doesn't stand for string in D. >>> >>> Yes it does. >> >> I was quoting bearophile's "it should error" post, you know that.

Re: static variables for non-constant expressions?

2011-04-11 Thread Steven Wawryk
On 12/04/11 07:36, Simon wrote: On 11/04/2011 22:15, Stewart Gordon wrote: On 11/04/2011 02:37, Jonathan M Davis wrote: I don't know the background of how static variables really work, so is there a good reason why the first function can't work like the one below it? They have to be calculat

Re: Should writef try to statically check for format specifiers?

2011-04-11 Thread Jesse Phillips
On Tue, 12 Apr 2011 01:55:24 +0200, Andrej Mitrovic wrote: > On 4/12/11, Jesse Phillips wrote: >> Andrej Mitrovic Wrote: >> >>> %s doesn't stand for string in D. >> >> Yes it does. > > I was quoting bearophile's "it should error" post, you know that. I do now. Though it still stands for string

Re: Should writef try to statically check for format specifiers?

2011-04-11 Thread bearophile
Jesse Phillips: > Two complaints: > > fprintf? A leading f is for file. > %s means format as a string not the type is a string. Sorry, you are right, I am silly. Bye, bearophile

Re: Should writef try to statically check for format specifiers?

2011-04-11 Thread Andrej Mitrovic
On 4/12/11, Jesse Phillips wrote: > Andrej Mitrovic Wrote: > >> %s doesn't stand for string in D. > > Yes it does. I was quoting bearophile's "it should error" post, you know that.

Re: Should writef try to statically check for format specifiers?

2011-04-11 Thread Jesse Phillips
bearophile Wrote: > So a solution is to build a fwrite/fwriteln that uses a compile-time string > for formatting, that performs compile-time tests using the more efficient > CTFE of DMD 2.053: > > int foo, bar; > fwriteln!"%d %s"(foo, bar); // compile-time error: bar isn't a string! Two compla

Re: Should writef try to statically check for format specifiers?

2011-04-11 Thread Jesse Phillips
Andrej Mitrovic Wrote: > %s doesn't stand for string in D. Yes it does. > My issue is that the arguments don't get printed out due to missing > specifiers. That is clearly a bug. But maybe it's not a huge bug since > it's just printing that is involved. I think it should do what it use to do w

Re: static variables for non-constant expressions?

2011-04-11 Thread Simon
On 11/04/2011 22:15, Stewart Gordon wrote: On 11/04/2011 02:37, Jonathan M Davis wrote: I don't know the background of how static variables really work, so is there a good reason why the first function can't work like the one below it? They have to be calculated at compile time so that orderi

Re: Should writef try to statically check for format specifiers?

2011-04-11 Thread Andrej Mitrovic
%s doesn't stand for string in D. My issue is that the arguments don't get printed out due to missing specifiers. That is clearly a bug. But maybe it's not a huge bug since it's just printing that is involved.

Re: Should writef try to statically check for format specifiers?

2011-04-11 Thread bearophile
Andrej Mitrovic: > I realize runtime checks would be out of the question, but I'm looking for > compile-time checks when it's possible to do so. GCC is often able to catch such bugs, but Walter has recently closed my enhancement request about this :-( http://d.puremagic.com/issues/show_bug.cgi?

Re: static variables for non-constant expressions?

2011-04-11 Thread Stewart Gordon
On 11/04/2011 02:37, Jonathan M Davis wrote: I don't know the background of how static variables really work, so is there a good reason why the first function can't work like the one below it? They have to be calculated at compile time so that ordering doesn't matter. If the order mattered, th

Re: What are delimited strings good for?

2011-04-11 Thread Stewart Gordon
On 10/04/2011 21:51, Jonathan M Davis wrote: If that had been `something instead of 'something, _then_ the delimited string becomes useful, but given how rarely backticks are needed, it does seem rather odd to have delimited strings just for that. So, I definitely have to wonder why they exist.

Should writef try to statically check for format specifiers?

2011-04-11 Thread Andrej Mitrovic
There is a bug here: import std.stdio; void main() { int index; writef("The index is", index); } Actually I found this bug in some example code: http://d.puremagic.com/issues/show_bug.cgi?id=5836 writef is missing a format specifier. But it still accepts this code. Is it possible fo

Re: "Before and after" in contracts?

2011-04-11 Thread spir
On 04/11/2011 09:18 PM, bearophile wrote: spir: Contracts, like any software tool, do not correctly match all possibly needs. This is true in general, but this isn't true in this case: here they don't match a basic need because D DbC misses a significant feature (prestate). If you take a lo

Re: "Before and after" in contracts?

2011-04-11 Thread bearophile
spir: > Contracts, like any software tool, do not correctly match all possibly needs. This is true in general, but this isn't true in this case: here they don't match a basic need because D DbC misses a significant feature (prestate). If you take a look at other implementations of DbC in Eiffel

Re: "Before and after" in contracts?

2011-04-11 Thread spir
On 04/11/2011 04:36 PM, Magnus Lie Hetland wrote: I guess I could just use a local variable (guarded by version()) and then have an assert() near the end of the function. Probably a better solution... If you mean coding your checking "by habd" inside the func's "normal" body, this seems to me

Re: How do I iterate over enum members at runtime?

2011-04-11 Thread Andrej Mitrovic
On 4/11/11, Dan Olson wrote: > I'm exploring more and found there is also std.traits.EnumMembers. It's > a little simpler: > > foreach (m; EnumMembers!Metrics)) > { > foo(m); > } > > And for number of members in enum Metrics > > EnumMembers!Metrics.length > Nice find, tha

Re: "Before and after" in contracts?

2011-04-11 Thread bearophile
Magnus Lie Hetland: > Yeah, that's what I've got right now. Just seems odd to need to use > attributes for this sort of thing. Also, it's rather brittle -- for > example, if the function (directly or indirectly) calls itself. Then > two (or more) pairs of in/out blocks will manipulate the same

Re: Why are unsigned to signed conversions implicit and don't emit a

2011-04-11 Thread bearophile
Kagamin: > bearophile Wrote: > > > - C# uses sbytes, and ubytes. Enough said. > > there's no ubyte in C# > It has byte, and it's unsigned. > > http://msdn.microsoft.com/en-us/library/exx3b86w.aspx I was partially wrong, thank you. If you take a look it has int/unt, short/ushort, etc, but it d

Re: Why are unsigned to signed conversions implicit and don't emit a

2011-04-11 Thread Kagamin
bearophile Wrote: > - C# uses sbytes, and ubytes. Enough said. there's no ubyte in C# It has byte, and it's unsigned. http://msdn.microsoft.com/en-us/library/exx3b86w.aspx

Re: "Before and after" in contracts?

2011-04-11 Thread Magnus Lie Hetland
On 2011-04-11 16:32:36 +0200, Kai Meyer said: I don't know if I can speak to the philosophical points here, but you can put your attribute declarations in a version block, and as long as the usage of that attribute is only used when that version is used, you should be fine. Yeah, that's what

Re: "Before and after" in contracts?

2011-04-11 Thread Kai Meyer
On 04/11/2011 06:05 AM, Magnus Lie Hetland wrote: I'd like to write a contract for a method to ensure that a given attribute does not decrease when calling the method. In order to do that, I need to store the "before" value, and compare it to the after value. My first intuition was to declare a

Re: Why are unsigned to signed conversions implicit and don't emit a warning?

2011-04-11 Thread Andrej Mitrovic
There are some aliases in std.stdint

Re: Why tuples? [was: Why tuple Re: Why are unsigned to signed conversions implicit...?]

2011-04-11 Thread Andrej Mitrovic
No reason. Sometimes I find a new feature in D and I like to try it out in my code in various places, to see how it looks, how it works, etc. In this case a simple struct would do. :)

"Before and after" in contracts?

2011-04-11 Thread Magnus Lie Hetland
I'd like to write a contract for a method to ensure that a given attribute does not decrease when calling the method. In order to do that, I need to store the "before" value, and compare it to the after value. My first intuition was to declare a variable in the in-block, and then access that

Re: Why are unsigned to signed conversions implicit and don't emit a warning?

2011-04-11 Thread spir
On 04/11/2011 10:10 AM, SimonM wrote: On 2011/04/11 09:31 AM, spir wrote: On 04/11/2011 02:42 AM, bearophile wrote: I and Don have asked (in Bugzilla and elsewhere) to change the built-in names into sbyte and ubyte, to avoid the common confusions between signed and unsigned bytes in D, but Walt

Re: Why tuples? [was: Why tuple Re: Why are unsigned to signed conversions

2011-04-11 Thread bearophile
spir: > I'm trying to understand why people use tuples (outside multiple return > values > and variadic typetuples). Why do you prefere the above to: Tuples are also sortable and printable on default, I think. Bye, bearophile

Re: COM objects

2011-04-11 Thread Richard Webb
You could try looking at the Juno or DWin projects on dsource. I've done a bit of COM stuff (both implementing com objects and using others) in Juno and it worked ok, though unfortunately it needs some changes to get it to work with the current D2.

COM objects

2011-04-11 Thread Sean Cavanaugh
I need some insight into how COM objects interoperate with D, as well as some advice on how to manage them properly. I've seen posts that IUnknown is treated specialy by the compiler, what is the nature of this behavior? Does this include any kind of AddRef/Release behavior integration with

Re: Why are unsigned to signed conversions implicit and don't emit a warning?

2011-04-11 Thread SimonM
On 2011/04/11 09:31 AM, spir wrote: On 04/11/2011 02:42 AM, bearophile wrote: I and Don have asked (in Bugzilla and elsewhere) to change the built-in names into sbyte and ubyte, to avoid the common confusions between signed and unsigned bytes in D, but Walter was deaf to this. I think a good n

Re: Why are unsigned to signed conversions implicit and don't emit a warning?

2011-04-11 Thread Andrew Wiley
On Sun, Apr 10, 2011 at 7:57 PM, Jonathan M Davis wrote: >> Andrej Mitrovic: >> > I just had a little bug in my code. In the WindowsAPI, there's this >> > alias: >> > >> > alias ubyte BYTE; >> > >> > Unfortunately I didn't check for this, and I erroneously assumed BYTE was >> > a signed value (bla

Re: Why are unsigned to signed conversions implicit and don't emit a

2011-04-11 Thread spir
On 04/11/2011 06:45 AM, bearophile wrote: - For me, and for Don and from other people that have had bugs in D caused by this, it seems they think of "bytes" as unsigned things. True for me as well. I was very surprised to discover 'byte' is /not/ unsigned (this was actually the cause of my fi

Re: Why are unsigned to signed conversions implicit and don't emit a warning?

2011-04-11 Thread spir
On 04/11/2011 02:42 AM, bearophile wrote: I and Don have asked (in Bugzilla and elsewhere) to change the built-in names into sbyte and ubyte, to avoid the common confusions between signed and unsigned bytes in D, but Walter was deaf to this. I think a good naming scheme would be: * signed

Why tuples? [was: Why tuple Re: Why are unsigned to signed conversions implicit...?]

2011-04-11 Thread spir
On 04/11/2011 01:47 AM, Andrej Mitrovic wrote: alias Tuple!(byte, "red", byte, "green", byte, "blue") RGBTuple; RGBTuple GetRGB(COLORREF cref) { RGBTuple rgb; rgb.red = GetRValue(cref); rgb.green = GetGValue(cref); rgb.blue = GetBValue(cref); return rgb; } [O your