Re: Static array size limit

2011-04-04 Thread simendsjo
And it seems also Walter is meaning mebibytes: enum size = (16*1024*1024)/int.sizeof; static assert(!__traits(compiles, int[size])); static assert(__traits(compiles, int[size-1]));

Re: Using opDispatch as *magic* getter/setter. Possible or not?

2011-04-04 Thread Simen kjaeraas
On Thu, 31 Mar 2011 02:32:35 +0200, Aleksandar Ružičić wrote: Is it possible to use opDispatch as generic getter and setter at the same time? Something like __get() and __set() in PHP.. this is what I've tried: https://gist.github.com/895571 and I get Error: template instance opDispatch!("b

Strange bug in std.concurrency.spawn

2011-04-04 Thread Jose Armando Garcia
dmd can compile and run to follow the code: unittest { spawn(&fun); } void fun(int i) { writeln(i); } Which if you are lucky segfaults and if you are unlucky prints garbage! The problem is that spawn doesn't checks that the signature of fun matches the number and type of variadic arguments. I

Re: Is there an equivalent to toStringz for wide strings?

2011-04-04 Thread Andrej Mitrovic
Ok that makes sense. Thank you.

Re: Is there an equivalent to toStringz for wide strings?

2011-04-04 Thread Jonathan M Davis
On 2011-04-04 16:44, Andrej Mitrovic wrote: > On 4/5/11, Jonathan M Davis wrote: > > Not to mention, in the case above, a null > > character should automatically be appended onto the end of the string, > > since it's as string literal. > > I've always found this confusing. So If I have this char

Re: Is there an equivalent to toStringz for wide strings?

2011-04-04 Thread Andrej Mitrovic
On 4/5/11, Jonathan M Davis wrote: > Not to mention, in the case above, a null > character should automatically be appended onto the end of the string, since > it's as string literal. I've always found this confusing. So If I have this char array: char[] foostring = "foo".dup; null is appended t

Re: Is there an equivalent to toStringz for wide strings?

2011-04-04 Thread Jonathan M Davis
On 2011-04-04 16:17, Andrej Mitrovic wrote: > I think I'd need a toWStringz function, or maybe toStringz can be made more > clever and figure out that I'm passing a wstring and return a > null-terminated wchar*. > > Currently I'm using wstrings and appending the null terminator by hand, > e.g.: >

Is there an equivalent to toStringz for wide strings?

2011-04-04 Thread Andrej Mitrovic
I think I'd need a toWStringz function, or maybe toStringz can be made more clever and figure out that I'm passing a wstring and return a null-terminated wchar*. Currently I'm using wstrings and appending the null terminator by hand, e.g.: wstring appName = "DMapp" ~ "\0"; Some WinAPI functio

Re: Static array size limit

2011-04-04 Thread Jonathan M Davis
On 2011-04-04 06:37, Steven Schveighoffer wrote: > On Sat, 02 Apr 2011 10:45:51 -0400, bearophile > > wrote: > > simendsjo: > >> http://digitalmars.com/d/2.0/arrays.html says static arrays are > >> limited to 16mb, but I can only allocate 1mb. > >> My fault, or bug? > > > > It accepts 4_000_000

Re: Array slices and copy on write

2011-04-04 Thread Steven Schveighoffer
On Mon, 04 Apr 2011 14:30:34 -0400, simendsjo wrote: On 04.04.2011 15:53, Steven Schveighoffer wrote: 2. The D GC collects entire memory blocks, not portions of them. There is no way for the GC to "collect" a[3]. It can only collect the entire memory block which contains a. Given the above

Re: Array slices and copy on write

2011-04-04 Thread simendsjo
On 04.04.2011 15:53, Steven Schveighoffer wrote: On Sun, 03 Apr 2011 08:29:47 -0400, simendsjo wrote: D will copy the original content if a slice expands, but is the following behavior implementation specific, or part of the specification? auto a = [0,1,2]; auto b = a[0..2]; a.length = 2; //

Re: How to spawn processes while keeping the parent process open ?

2011-04-04 Thread Tarun Ramakrishna
Hi Kai, Thanks. Yes, I came to realize that myself. Since I didn't see a fork in std.process, I assumed it was different from the POSIX semantics. Thanks, Tarun On Mon, Apr 4, 2011 at 8:32 PM, Kai Meyer wrote: > On 04/03/2011 07:31 AM, Tarun Ramakrishna wrote: >> >> Hi, >> >> Apparently std.pro

Re: Static array size limit

2011-04-04 Thread Steven Schveighoffer
On Mon, 04 Apr 2011 12:43:03 -0400, bearophile wrote: Steven Schveighoffer: That would be 16 MiB. http://en.wikipedia.org/wiki/Mebibyte Then I think 16 MiB are more useful than 16_000_000 bytes. Seems arbitrary to me. I'm sure some people feel 32MB would be more useful. -Steve

Re: Static array size limit

2011-04-04 Thread bearophile
Steven Schveighoffer: > That would be 16 MiB. > > http://en.wikipedia.org/wiki/Mebibyte Then I think 16 MiB are more useful than 16_000_000 bytes. Bye, bearophile

Re: Array operation doesn't check array bounds

2011-04-04 Thread Kai Meyer
On 04/03/2011 05:06 PM, Jonathan M Davis wrote: On 2011-04-03 04:10, simendsjo wrote: int[] a = [1,2,3]; int[4] b; assert(b == [0,0,0,0]); b = a[] * 3; // oops... a[] * 3 takes element outside a's bounds assert(b[$-1] == 0); // fails.. last element is *(a

Re: How to spawn processes while keeping the parent process open ?

2011-04-04 Thread Kai Meyer
On 04/03/2011 07:31 AM, Tarun Ramakrishna wrote: Hi, Apparently std.process.exec (D2.052/windows) doesn't work the way the documentation describes. It terminates the parent process. Is there a way to keep the parent process open in D ? I also vaguely remember seeing some mails on this list about

Re: Array slices and copy on write

2011-04-04 Thread Steven Schveighoffer
On Sun, 03 Apr 2011 08:29:47 -0400, simendsjo wrote: D will copy the original content if a slice expands, but is the following behavior implementation specific, or part of the specification? auto a = [0,1,2]; auto b = a[0..2]; a.length = 2; // is a[3] already marked

Re: Static array size limit

2011-04-04 Thread Steven Schveighoffer
On Sat, 02 Apr 2011 10:45:51 -0400, bearophile wrote: simendsjo: http://digitalmars.com/d/2.0/arrays.html says static arrays are limited to 16mb, but I can only allocate 1mb. My fault, or bug? It accepts 4_000_000 ints, but not (16 * 1024 * 1024) / int.sizeof = 4_194_304 ints. I don't k

Re: How to check if an array is a manifest constant?

2011-04-04 Thread Jonathan M Davis
On 2011-04-04 03:11, simendsjo wrote: > > What use case do you have for wanting to know whether a variable is an > > enum or not? > > The same reason I'd like to check if it's const/immutable; if an algorithm > requires a modifiable array. > > void sortInPlace(int[] array) { > array.sort; > }

Re: How to check if an array is a manifest constant?

2011-04-04 Thread simendsjo
> What use case do you have for wanting to know whether a variable is an enum > or not? The same reason I'd like to check if it's const/immutable; if an algorithm requires a modifiable array. void sortInPlace(int[] array) { array.sort; } void main() { int[] a = [3,2,1]; sortInPlace

Re: How to check if an array is a manifest constant?

2011-04-04 Thread Jonathan M Davis
On 2011-04-04 01:16, simendsjo wrote: > But there is a difference in how they behave, and I have no way of checking > this behavior. Consider the following little snippet: > > void f(int[] a) { > a[0] = -1; > } > > void main() { > int[] a = [1,2,3]; > static assert(is(typeof(a) == int

Re: How to check if an array is a manifest constant?

2011-04-04 Thread simendsjo
But there is a difference in how they behave, and I have no way of checking this behavior. Consider the following little snippet: void f(int[] a) { a[0] = -1; } void main() { int[] a = [1,2,3]; static assert(is(typeof(a) == int[])); f(a); assert(a[0] == -1); // a passed by re

Re: Trying to compile sample from The D Programming Language book.

2011-04-04 Thread Jesus Alvarez
I reported the error to the author. Thanks guys! On Sun, Apr 3, 2011 at 3:34 AM, spir wrote: > On 04/03/2011 09:38 AM, Jesus Alvarez wrote: > >> I got it to compile adding std.regex to split to make it: >> >> auto words = std.regex.split (sentence, regex("[ \t,.;:?]+")); >> >> So now my question