CTFE and cast

2012-01-13 Thread k2
When replace typedef to enum, it became impossible to compile a certain portion. dmd v2.057 Windows enum HANDLE : void* {init = (void*).init} pure HANDLE int_to_HANDLE(int x) { return cast(HANDLE)x; } void bar() { HANDLE a = cast(HANDLE)1;//

Streams vs ranges

2012-01-13 Thread Piotr Szturmaj
Is there a plan to replace streams with byte ranges? Or should I just use streams? I need to do some binary parsing and I found using ranges is not very comfortable. For example to read an uint I need to: version (LittleEndian) auto r = retro(takeExactly(range, 4)); else auto r =

Fast way to append to an SList

2012-01-13 Thread Fernando Carvajal
I need a fast way to append to an SList. I was thinking of using insertAfter() and keep track of a range that points to the end of the list but, after appending an item, how would you get the new range to the end? This is what I had planned: List!int list; Range end = list[];

Re: Streams vs ranges

2012-01-13 Thread Jonathan M Davis
On Friday, January 13, 2012 12:17:06 Piotr Szturmaj wrote: Is there a plan to replace streams with byte ranges? Or should I just use streams? At some point, std.stream will be replace with a range-based API. There has been some discussion on the design, but it hasn't been fully fleshed out,

Re: opApply with/without ref

2012-01-13 Thread bearophile
H. S. Teoh: void opApply(int delegate(ref uint n) cb) const { Use const ref: void opApply(int delegate(const ref uint n) cb) const { Bye, bearophile

Re: CTFE and cast

2012-01-13 Thread Don Clugston
On 13/01/12 10:01, k2 wrote: When replace typedef to enum, it became impossible to compile a certain portion. dmd v2.057 Windows enum HANDLE : void* {init = (void*).init} pure HANDLE int_to_HANDLE(int x) { return cast(HANDLE)x; }

Re: CTFE and cast

2012-01-13 Thread Piotr Szturmaj
Don Clugston wrote: On 13/01/12 10:01, k2 wrote: When replace typedef to enum, it became impossible to compile a certain portion. dmd v2.057 Windows enum HANDLE : void* {init = (void*).init} pure HANDLE int_to_HANDLE(int x) { return

Re: Streams vs ranges

2012-01-13 Thread Piotr Szturmaj
Jonathan M Davis wrote: On Friday, January 13, 2012 12:17:06 Piotr Szturmaj wrote: Is there a plan to replace streams with byte ranges? Or should I just use streams? At some point, std.stream will be replace with a range-based API. There has been some discussion on the design, but it hasn't

Re: Fast way to append to an SList

2012-01-13 Thread Steven Schveighoffer
On Fri, 13 Jan 2012 06:34:39 -0500, Fernando Carvajal fernandocarva...@mailinator.com wrote: I need a fast way to append to an SList. I was thinking of using insertAfter() and keep track of a range that points to the end of the list but, after appending an item, how would you get the new

Re: opApply with/without ref

2012-01-13 Thread H. S. Teoh
On Fri, Jan 13, 2012 at 07:36:40AM -0500, bearophile wrote: H. S. Teoh: void opApply(int delegate(ref uint n) cb) const { Use const ref: void opApply(int delegate(const ref uint n) cb) const { [...] Thanks a lot! That works like a charm! T -- Let's not fight disease by

Re: opApply with/without ref

2012-01-13 Thread Steven Schveighoffer
On Thu, 12 Jan 2012 22:49:49 -0500, H. S. Teoh hst...@quickfur.ath.cx wrote: Hi all, I'm experimenting with overloading foreach() with opApply, and I found that this code doesn't compile: class C { void opApply(int delegate(uint n) cb) const {

Error creating thread

2012-01-13 Thread exec
I'm currently fiddling around with some stuff, and I was curious how well thousands of threads run simultaneously. The problem now is, that I'm often running into the following exception: core.thread.ThreadException@src\core\thread.d(817): Error creating thread Here's my test program:

Re: Error creating thread

2012-01-13 Thread H. S. Teoh
On Fri, Jan 13, 2012 at 08:42:51PM +0100, exec wrote: I'm currently fiddling around with some stuff, and I was curious how well thousands of threads run simultaneously. The problem now is, that I'm often running into the following exception: core.thread.ThreadException@src\core\thread.d(817):

Re: Error creating thread

2012-01-13 Thread Jonathan M Davis
On Friday, January 13, 2012 11:52:00 H. S. Teoh wrote: On Fri, Jan 13, 2012 at 08:42:51PM +0100, exec wrote: I'm currently fiddling around with some stuff, and I was curious how well thousands of threads run simultaneously. The problem now is, that I'm often running into the following

const violation?

2012-01-13 Thread H. S. Teoh
Why does the following code compile? import std.stdio; int f(ref int x) { return x++; } class A { int x=123; int g() const { return f(x); } } void main() {

Re: const violation?

2012-01-13 Thread Steven Schveighoffer
On Fri, 13 Jan 2012 15:27:56 -0500, H. S. Teoh hst...@quickfur.ath.cx wrote: Why does the following code compile? import std.stdio; int f(ref int x) { return x++; } class A { int x=123; int g() const {

Re: Error creating thread

2012-01-13 Thread exec
On Friday, 13 January 2012 at 20:02:21 UTC, Jonathan M Davis wrote: Yeah. You can have user-defined limits too. IIRC, on Linux, the default thread limit per user is 1024 threads, whereas the system limit is over 60,000. The limits can be tweaked if you need to though. I assume that the

Absolute beginner

2012-01-13 Thread Jorge
My first question si very silly: string str = readln() my input is for example 123 how can i convert this to an integer? Thanks.

Re: Absolute beginner

2012-01-13 Thread Piotr Szturmaj
Jorge wrote: My first question si very silly: string str = readln() my input is for example 123 how can i convert this to an integer? import std.conv; // then in code: auto i = to!int(str);

A tutorial on D templates

2012-01-13 Thread Philippe Sigaud
[Cross-posted with D.announce, since it's also an annoucement] Hello all, I discovered D a few years ago and, seeing the recent increase in community projects, I looked for a way to bring my own small part to it. I quite like D templates and wanted to try LaTeX again, so I decided to bite the

Re: Absolute beginner

2012-01-13 Thread Joshua Reusch
Am 13.01.2012 22:16, Piotr Szturmaj wrote: Jorge wrote: My first question si very silly: string str = readln() my input is for example 123 how can i convert this to an integer? import std.conv; // then in code: auto i = to!int(str); the string returned by readln() ends with NL ('\n'),

Re: Absolute beginner

2012-01-13 Thread Jorge
Ok, it works fine. Thx to you all ;-) and sorry for my noob question.

Re: Absolute beginner

2012-01-13 Thread Matej Nanut
You could also try to!int(str.strip), strip() removes whitespace from the left and right of a string. You have to import std.string for it. On 13 January 2012 22:34, Joshua Reusch yos...@arkandos.de wrote: Am 13.01.2012 22:16, Piotr Szturmaj wrote: Jorge wrote: My first question si very

Re: Absolute beginner

2012-01-13 Thread Timon Gehr
On 01/13/2012 10:34 PM, Jorge wrote: Thanks for your answer but: import std.stdio; import std.conv; void main() { write(Insert number: ); string s = readln(); auto i = to!int(s); } compiles but after i enter a number and press the enter key i get:

Re: Absolute beginner

2012-01-13 Thread bearophile
Timon Gehr: readln() includes the trailing newline character in the resulting string. You can use std.string.strip to remove leading and trailing whitespace: Time ago I have asked Andrei to modify the to!int conversion to work as Python, ignoring leading and trailing whitespace: s =

Re: Absolute beginner

2012-01-13 Thread Matej Nanut
While we're at it: what's the best way to parse in a formatted manner? For example, if I want to get 5 hexadecimal digits converted into an uint? And I want to simultaneously advance the string? sscanf seems fiddly and unsafe. On 13 January 2012 22:56, bearophile bearophileh...@lycos.com wrote:

Re: A tutorial on D templates

2012-01-13 Thread DNewbie
I can't understand it. Why would someone need template programming. What problem does template solve? -- D

Re: A tutorial on D templates

2012-01-13 Thread Peter Alexander
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? Suppose you want to write a function to get the minimum of two integers. It's easy: int min(int a, int b) { return a b ? a : b; } Suppose then

Re: A tutorial on D templates

2012-01-13 Thread DNewbie
On Fri, Jan 13, 2012, at 11:28 PM, Peter Alexander 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? Suppose you want to write a function to get the minimum of two integers. It's easy:

Re: A tutorial on D templates

2012-01-13 Thread Ali Çehreli
On 01/13/2012 02:48 PM, DNewbie wrote: I can't understand it. Why would someone need template programming. What problem does template solve? 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

Re: Absolute beginner

2012-01-13 Thread H. S. Teoh
On Fri, Jan 13, 2012 at 11:05:19PM +0100, Matej Nanut wrote: While we're at it: what's the best way to parse in a formatted manner? For example, if I want to get 5 hexadecimal digits converted into an uint? [...] Have you tried: import std.conv; ... uint val =

Re: Absolute beginner

2012-01-13 Thread Justin Whear
On Fri, 13 Jan 2012 23:05:19 +0100, Matej Nanut wrote: While we're at it: what's the best way to parse in a formatted manner? For example, if I want to get 5 hexadecimal digits converted into an uint? And I want to simultaneously advance the string? sscanf seems fiddly and unsafe. Check

std.algorithm.startsWith with maximal matching

2012-01-13 Thread H. S. Teoh
Hi all, I'm reading the docs for startsWith(A,B...) with multiple ranges in B, and it seems that it will always match the *shortest* range whenever more than one range in B matches. Is there a way to make it always match the *longest* range instead? Or do I have to write my own function for that?

Re: std.algorithm.startsWith with maximal matching

2012-01-13 Thread Jonathan M Davis
On Friday, January 13, 2012 16:48:00 H. S. Teoh wrote: Hi all, I'm reading the docs for startsWith(A,B...) with multiple ranges in B, and it seems that it will always match the *shortest* range whenever more than one range in B matches. Is there a way to make it always match the *longest*

Re: std.algorithm.startsWith with maximal matching

2012-01-13 Thread H. S. Teoh
On Fri, Jan 13, 2012 at 09:36:07PM -0500, Jonathan M Davis wrote: On Friday, January 13, 2012 16:48:00 H. S. Teoh wrote: Hi all, I'm reading the docs for startsWith(A,B...) with multiple ranges in B, and it seems that it will always match the *shortest* range whenever more than one

function pointer from DLL

2012-01-13 Thread DNewbie
I've been trying to translate the following from http://www.scintilla.org/Steps.html int (*fn)(void*,int,int,int); void * ptr; int canundo; fn = (int (__cdecl *)(void *,int,int,int))SendMessage( hwndScintilla,SCI_GETDIRECTFUNCTION,0,0); ptr = (void

Re: function pointer from DLL

2012-01-13 Thread Andrej Mitrovic
You can clone this: g...@github.com:AndrejMitrovic/DSciteWin.git Then just run build.bat.

Re: function pointer from DLL

2012-01-13 Thread Andrej Mitrovic
On 1/14/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: You can clone this: g...@github.com:AndrejMitrovic/DSciteWin.git Then just run build.bat. Sorry, I've assumed you run git, the http link is: https://github.com/AndrejMitrovic/DSciteWin

Re: function pointer from DLL

2012-01-13 Thread DNewbie
On Sat, Jan 14, 2012, at 06:04 AM, Andrej Mitrovic wrote: On 1/14/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: You can clone this: g...@github.com:AndrejMitrovic/DSciteWin.git Then just run build.bat. Sorry, I've assumed you run git, the http link is:

Re: function pointer from DLL

2012-01-13 Thread Andrej Mitrovic
Your problem was that you didn't cast the function pointer to an extern(C) function. Unfortunately you can't do this inline (I can't tell if this will be fixed or not), so you have to use an alias as a workaround: alias extern (C) int function(void*,int,int,int) SciFnDirect; fn =

Re: std.algorithm.startsWith with maximal matching

2012-01-13 Thread Jonathan M Davis
On Friday, January 13, 2012 18:47:19 H. S. Teoh wrote: On Fri, Jan 13, 2012 at 09:36:07PM -0500, Jonathan M Davis wrote: On Friday, January 13, 2012 16:48:00 H. S. Teoh wrote: Hi all, I'm reading the docs for startsWith(A,B...) with multiple ranges in B, and it seems that it