Re: Segfault with std.container.Array but not regular dynamic array

2012-11-29 Thread Maxim Fomin
On Wednesday, 28 November 2012 at 22:13:05 UTC, Dan wrote: On Wednesday, 28 November 2012 at 20:30:41 UTC, Maxim Fomin wrote: On Wednesday, 28 November 2012 at 18:08:59 UTC, Dan wrote: This code with version=bug produces garbage because of opAssign. It seems that opAssign is actually called

Re: assertion failure with template instantiation of forward reference class

2012-11-29 Thread comco
On Thursday, 29 November 2012 at 01:38:50 UTC, bearophile wrote: comco: Looks like a bug? This is what DMD 2.061alpha prints, it doesn't crash: ...\dmd2\src\phobos\std\range.d(603): Error: static assert Cannot put a string into a LockingTextWriter ...\dmd2\src\phobos\std\format.d(2349):

Re: Is there a portable way to limit memory/cpu usage of a D application?

2012-11-29 Thread Dejan Lekic
On Thursday, 29 November 2012 at 04:44:34 UTC, Mike Young wrote: On Wednesday, 9 November 2011 at 17:13:14 UTC, Dejan Lekic wrote: Sure nothing prevents me from using setrlimit() in my D app, but perhaps it is something to think about a portable way of doing that. I know I'm over a year

static assert

2012-11-29 Thread Jack Applegame
Another funny thing. import std.conv; static assert(0, 1 != ~ text(2)); outputs Error: static assert ['1',' ','!','=',' ','2']

Re: static assert

2012-11-29 Thread bearophile
Jack Applegame: import std.conv; static assert(0, 1 != ~ text(2)); outputs Error: static assert ['1',' ','!','=',' ','2'] This is known problem, it's already in Bugzilla, and maybe there's already a patch for it (there are about one hundred patches waiting in Bugzilla). Bye, bearophile

Re: Segfault with std.container.Array but not regular dynamic array

2012-11-29 Thread Dan
On Thursday, 29 November 2012 at 07:59:02 UTC, Maxim Fomin wrote: This doesn't look like assembly for previous source. Please provide the source for which you have assembly and tell which dmd options do you use. Well, I'm using the latest dmd (from the trunk), phobos, druntime, so I could

canFind typing

2012-11-29 Thread bearophile
I have used std.algorithm.canFind with different tuple types by mistake, and the compiler has not complained. So to show it I have written some reduced code that uses just numbers: import std.algorithm: canFind; void main() { int[] arr1 = [1, 2]; double x1 = 2.0;

Re: telnet and D

2012-11-29 Thread maarten van damme
vibe.d is very modular, just import what you need. I hate to push it, but it has very good documentation and examples. Its designed for web apps, but it makes a nice little web library as well. import vibe.vibe; void main() { auto client = new HttpClient;

Re: Segfault with std.container.Array but not regular dynamic array

2012-11-29 Thread Maxim Fomin
On Thursday, 29 November 2012 at 12:38:03 UTC, Dan wrote: On Thursday, 29 November 2012 at 07:59:02 UTC, Maxim Fomin wrote: This doesn't look like assembly for previous source. Please provide the source for which you have assembly and tell which dmd options do you use. Well, I'm using the

Re: Calls to struct methods and immutable

2012-11-29 Thread Joseph Rushton Wakeling
On 11/27/2012 05:31 PM, Dan wrote: I'm using a custom gdup that recursively copies fields and requires no support from nested structs. If a dup is provided by a struct it will be called. No guarantees, but have a look. https://github.com/patefacio/d-help/blob/master/d-help/opmix/mix.d Thanks

Can operators return type?

2012-11-29 Thread Zhenya
Hi! It would useful for some my project,if operators could be a template,that return type.Something like alias TypeTuple!(int,char) types; static assert(types[1] == char) //opIndex So can I define something like that?

Re: opSlice Bug?

2012-11-29 Thread Ali Çehreli
On 11/29/2012 08:15 AM, Namespace wrote: Why I have to write arr2[] += arr[][] instead of arr2[] += arr[] ? Bug or 'feature'? :P Code: http://dpaste.dzfl.pl/4c732f4c opSplice, eh? Is that another undocumented feature or one that has been deprecated? Ali

Re: opSlice Bug?

2012-11-29 Thread Namespace
On Thursday, 29 November 2012 at 16:46:45 UTC, Ali Çehreli wrote: On 11/29/2012 08:15 AM, Namespace wrote: Why I have to write arr2[] += arr[][] instead of arr2[] += arr[] ? Bug or 'feature'? :P Code: http://dpaste.dzfl.pl/4c732f4c opSplice, eh? Is that another undocumented feature or one

Re: Can operators return type?

2012-11-29 Thread bearophile
Zhenya: It would useful for some my project,if operators could be a template,that return type. D operators are functions, and D functions return values. And in D types are not values (unlike Python and several other languages), unless you use a Typeinfo or something. Maybe if you explain

Re: opSlice Bug?

2012-11-29 Thread bearophile
Ali Çehreli: opSplice, eh? Is that another undocumented feature or one that has been deprecated? I think it's not deprecated: http://dlang.org/operatoroverloading.html#Slice Bye, bearophile

Re: Can operators return type?

2012-11-29 Thread Simen Kjaeraas
On 2012-11-29, 17:33, Zhenya wrote: Hi! It would useful for some my project,if operators could be a template,that return type.Something like alias TypeTuple!(int,char) types; static assert(types[1] == char) //opIndex So can I define something like that? This works out of the box. If you

Re: opSlice Bug?

2012-11-29 Thread Ali Çehreli
On 11/29/2012 08:50 AM, Namespace wrote: On Thursday, 29 November 2012 at 16:46:45 UTC, Ali Çehreli wrote: On 11/29/2012 08:15 AM, Namespace wrote: Why I have to write arr2[] += arr[][] instead of arr2[] += arr[] ? Bug or 'feature'? :P Code: http://dpaste.dzfl.pl/4c732f4c opSplice, eh? Is

Re: opSlice Bug?

2012-11-29 Thread Namespace
Yes, that could be better (but I don't like it), but my code should compile as well, or not?

Re: opSlice Bug?

2012-11-29 Thread Ali Çehreli
On 11/29/2012 08:15 AM, Namespace wrote: Why I have to write arr2[] += arr[][] instead of arr2[] += arr[] ? Bug or 'feature'? :P Code: http://dpaste.dzfl.pl/4c732f4c Apparently, the array-wise operations require the following syntax: a[] += b[]; In other words, the compiler wants to see

Re: opSlice Bug?

2012-11-29 Thread Namespace
That is what I thought also. That is awfully and limited. :/

Initializing values in associative arrays

2012-11-29 Thread Joseph Rushton Wakeling
How safe is it to rely on doing something like this: uint[size_t] x; foreach(i; iota(0, 10)) x[i]++; foreach(i; iota(5, 15)) x[i]++; ... ? In this case correct output comes out -- that is, values for keys 1-4 and 10-14 come out as 1, values for keys 5-9 come out

Re: canFind typing

2012-11-29 Thread bearophile
Jonathan M Davis: Why wouldn't they be? You can compare int and double, and that's what find and canFind care about. Right, it's a matter of equality operator. In my code I was performing canFind on an array of tuples. So I didn't realize that the following code (where both tuple field

Re: Initializing values in associative arrays

2012-11-29 Thread bearophile
Joseph Rushton Wakeling: How safe is it to rely on doing something like this: uint[size_t] x; foreach(i; iota(0, 10)) x[i]++; foreach(i; iota(5, 15)) x[i]++; This is part of the D associative array specs, so in theory it's safe, but you have to keep this

Re: Apparent problem with GC not collecting on Windows

2012-11-29 Thread Michael
Because you used uint instead of ubyte, array is bigger, memory exhausts faster. Oh, I see. 3. Why it helps? GC.free(data.ptr); Initial leak happened because for some reason array allocated in previous iteration was not collected by GC when allocating new one, so the new one was allocated

Re: Calls to struct methods and immutable

2012-11-29 Thread Dan
On Thursday, 29 November 2012 at 16:28:42 UTC, Joseph Rushton Wakeling wrote: My one caveat here is that in general I'm reluctant to rely too strongly on 3rd-party libraries at this stage of D's development. That's particularly true where stuff like this is concerned -- which might well be

Re: Apparent problem with GC not collecting on Windows

2012-11-29 Thread Ali Çehreli
On 11/29/2012 12:06 PM, Michael wrote: Because you used uint instead of ubyte, array is bigger, memory exhausts faster. Oh, I see. 3. Why it helps? GC.free(data.ptr); Initial leak happened because for some reason array allocated in previous iteration was not collected by GC when

Re: Segfault with std.container.Array but not regular dynamic array

2012-11-29 Thread Dan
On Thursday, 29 November 2012 at 15:06:07 UTC, Maxim Fomin wrote: On Thursday, 29 November 2012 at 12:38:03 UTC, Dan wrote: On Thursday, 29 November 2012 at 07:59:02 UTC, Maxim Fomin wrote: This doesn't look like assembly for previous source. Please provide the source for which you have

Re: Can operators return type?

2012-11-29 Thread Zhenya
On Thursday, 29 November 2012 at 16:55:01 UTC, bearophile wrote: Zhenya: It would useful for some my project,if operators could be a template,that return type. D operators are functions, and D functions return values. And in D types are not values (unlike Python and several other

Re: Can operators return type?

2012-11-29 Thread bearophile
Zhenya: For example: struct MyIntType { alias int type; template opSlice() { alias type opSlice; } As you guess, this is not supported in D. Bye, bearophile

Re: Can operators return type?

2012-11-29 Thread Zhenya
On Thursday, 29 November 2012 at 21:53:20 UTC, bearophile wrote: Zhenya: For example: struct MyIntType { alias int type; template opSlice() { alias type opSlice; } As you guess, this is not supported in D. Bye, bearophile Thank you,understood(

Newb's questions constructor

2012-11-29 Thread js.mdnq
Reading 'the book' and it states that D does not allow one to nest construction calls that are not complete. e.g., this() { if (x 1) { this(x); } } will fail. First, I do not know why this is required. It seems to me it would be better to allow one optionally use another constructor if

Templated Function pointers

2012-11-29 Thread js.mdnq
I need to store a templated function in a function pointer, how can I do this? e.g., void function(double) myfuncptr; void myfunc(double d) { } myfuncptr = myfunc; Now I would like to use a template parameter instead of double. In C++ one can do this by using boosts binding's and

prune with dirEntries

2012-11-29 Thread Dan
Is there a way to walk files with std.file.dirEntries such that certain directories are skipped (i.e. how to avoid .git entirely/recursively)? Thanks Dan

Re: prune with dirEntries

2012-11-29 Thread Jonathan M Davis
On Friday, November 30, 2012 01:24:07 Dan wrote: Is there a way to walk files with std.file.dirEntries such that certain directories are skipped (i.e. how to avoid .git entirely/recursively)? You can use std.algorithm.filter on its result. Then when it would iterate to something which doesn't

Re: prune with dirEntries

2012-11-29 Thread Dan
On Friday, 30 November 2012 at 01:13:13 UTC, Jonathan M Davis wrote: On Friday, November 30, 2012 01:24:07 Dan wrote: Is there a way to walk files with std.file.dirEntries such that certain directories are skipped (i.e. how to avoid .git entirely/recursively)? You can use std.algorithm.filter

Re: prune with dirEntries

2012-11-29 Thread Jonathan M Davis
On Friday, November 30, 2012 02:57:20 Dan wrote: On Friday, 30 November 2012 at 01:13:13 UTC, Jonathan M Davis wrote: On Friday, November 30, 2012 01:24:07 Dan wrote: Is there a way to walk files with std.file.dirEntries such that certain directories are skipped (i.e. how to avoid .git

Type converter from build in to user type

2012-11-29 Thread js.mdnq
I have a struct I am trying convert from int's to the type. Since I can't add a opCast overload to an int I don't know how to do it. My opCast convertors in my class do not work for the assignment operator: class myType { opCast, opAssign } mytype = 3; Error that we can't convert an int

Re: Type converter from build in to user type

2012-11-29 Thread Jonathan M Davis
On Friday, November 30, 2012 03:59:05 js.mdnq wrote: I have a struct I am trying convert from int's to the type. Since I can't add a opCast overload to an int I don't know how to do it. My opCast convertors in my class do not work for the assignment operator: class myType { opCast,

Re: Type converter from build in to user type

2012-11-29 Thread jerro
On Friday, 30 November 2012 at 02:59:06 UTC, js.mdnq wrote: I have a struct I am trying convert from int's to the type. Since I can't add a opCast overload to an int I don't know how to do it. My opCast convertors in my class do not work for the assignment operator: class myType {

Re: Type converter from build in to user type

2012-11-29 Thread Ali Çehreli
On 11/29/2012 07:24 PM, jerro wrote: On Friday, 30 November 2012 at 02:59:06 UTC, js.mdnq wrote: I have a struct I am trying convert from int's to the type. Since I can't add a opCast overload to an int I don't know how to do it. My opCast convertors in my class do not work for the assignment

Re: Calls to struct methods and immutable

2012-11-29 Thread Ali Çehreli
On 11/27/2012 06:05 AM, Joseph Rushton Wakeling wrote: On 11/27/2012 01:16 PM, Joseph Rushton Wakeling wrote: immutable(Node) idup() pure const @property { auto linkCopy = to!(Link[])(links); immutable ilinks = assumeUnique(linkCopy); return immutable(Node)(id, ilinks); } Actually I'm being

Re: prune with dirEntries

2012-11-29 Thread Joshua Niehus
On Friday, 30 November 2012 at 01:57:21 UTC, Dan wrote: That will do the filtering correctly - but what I was hoping was to actually prune at the directory level and not drill down to the files in of an unwanted directory (e.g. .git). The problem with this and what I'm trying to overcome is

Re: prune with dirEntries

2012-11-29 Thread Joshua Niehus
On Friday, 30 November 2012 at 06:29:01 UTC, Joshua Niehus wrote: I think if you go breadth first, you can filter out the unwanted directories before it delves into them oh wait... it probably still looks through all those dir's. What about this? import std.algorithm, std.regex, std.stdio,