Re: A tutorial on D templates

2012-01-14 Thread Philippe Sigaud
On 13/01/12 10:48 PM, DNewbie wrote: I can't understand it. Why would someone need template programming. What problem does template solve? Well read on and see :-) Peter: Suppose you want to write a function to get the minimum of two integers. It's easy: Oh.. I see. Thank you

Re: A tutorial on D templates

2012-01-14 Thread Philippe Sigaud
On Sat, Jan 14, 2012 at 01:08, Ali Çehreli acehr...@yahoo.com wrote: Here is another resource that tries to answer that question:  http://ddili.org/ders/d.en/templates.html Parts of the source code may be left to the compiler to be filled in until that part is actually used in the program.

Re: A tutorial on D templates

2012-01-14 Thread Ali Çehreli
On 01/14/2012 12:11 AM, Philippe Sigaud wrote: On Sat, Jan 14, 2012 at 01:08, Ali Çehreliacehr...@yahoo.com wrote: http://ddili.org/ders/d.en/templates.html Hi Ali, I discovered you had a chapter on templates just a few days ago. That chapter is intentionally incomplete. I think

Re: A tutorial on D templates

2012-01-14 Thread Philippe Sigaud
On Sat, Jan 14, 2012 at 15:56, Ali Çehreli acehr...@yahoo.com wrote: On 01/14/2012 12:11 AM, Philippe Sigaud wrote: On Sat, Jan 14, 2012 at 01:08, Ali Çehreliacehr...@yahoo.com  wrote:   http://ddili.org/ders/d.en/templates.html Hi Ali, I discovered you had a chapter on templates just a few

Re: A tutorial on D templates

2012-01-14 Thread DNewbie
On Sat, Jan 14, 2012, at 09:07 AM, Philippe Sigaud wrote: On 13/01/12 10:48 PM, DNewbie wrote: I can't understand it. Why would someone need template programming. What problem does template solve? Well read on and see :-) Peter: Suppose you want to write a function to get the

Re: import std.c.windows.windows;

2012-01-14 Thread DNewbie
On Wed, Jan 11, 2012, at 01:16 PM, Mike Parker wrote: On 1/10/2012 10:57 PM, DNewbie wrote: On Tue, Jan 10, 2012, at 10:37 PM, Mike Parker wrote: Those samples use a binding to the Win32 API[1] that does not ship with DMD. So in your case, std.c.windows.windows is probably what you want

Constant function/delegate literal

2012-01-14 Thread Vladimir Matveev
Hi, Is there a reason why I cannot compile the following code: module test; struct Test { int delegate(int) f; } Test s = Test((int x) { return x + 1; }); void main(string[] args) { return; } dmd 2.057 says: test.d(7): Error: non-constant expression cast(int delegate(int))delegate

Re: A tutorial on D templates

2012-01-14 Thread Joel
Good work Philippe, looks good!

Re: Absolute beginner

2012-01-14 Thread Matej Nanut
I've never noticed std.conv.parse takes a radix argument, silly me. And will take a look at readf from std.stream, definitely. Thanks! On 14 January 2012 01:20, Justin Whear jus...@economicmodeling.com wrote: On Fri, 13 Jan 2012 23:05:19 +0100, Matej Nanut wrote: While we're at it: what's the

Re: Constant function/delegate literal

2012-01-14 Thread Andrej Mitrovic
I guess these are CTFE (compile-time function evaluation) issues, someone else might know more. A workaround is to use a module constructor which will run before main(): struct Test { int delegate(int) f; } Test s; static this() { s = Test((int x) { return x + 1; }); } Note that 's' is

Re: Fixed matrix rows joining

2012-01-14 Thread Andrej Mitrovic
A rectangular array is really just one array, is it not? From a syntax point it looks like a multidimensional array but really it's just a single linear piece of memory, so just cast it: void main() { int[2][4] table; table[0][] = 0; table[1][] = 1; table[2][] = 2; table[3][]

Re: Fixed matrix rows joining

2012-01-14 Thread Andrej Mitrovic
I guess join() could be specialized for static arrays and then just do a dup and a cast? Would that work ok?

Re: std.algorithm.startsWith with maximal matching

2012-01-14 Thread H. S. Teoh
On Fri, Jan 13, 2012 at 09:30:35PM -0800, Jonathan M Davis wrote: On Friday, January 13, 2012 18:47:19 H. S. Teoh wrote: [...] But what I really want to accomplish is to parse a string containing multiple words; at each point I have a list of permitted words that need to be matched against

Re: std.algorithm.startsWith with maximal matching

2012-01-14 Thread Jonathan M Davis
On Saturday, January 14, 2012 19:13:02 H. S. Teoh wrote: On Fri, Jan 13, 2012 at 09:30:35PM -0800, Jonathan M Davis wrote: On Friday, January 13, 2012 18:47:19 H. S. Teoh wrote: [...] But what I really want to accomplish is to parse a string containing multiple words; at each point I

Re: std.algorithm.startsWith with maximal matching

2012-01-14 Thread Jonathan M Davis
On Saturday, January 14, 2012 19:45:55 Jonathan M Davis wrote: If you have to worry about punctuation, then == isn't going to work. You'll need to use some other combination of functions to strip the punctuation from one or both ends of the word. One possible solution would be something like