Re: char[][] join == string
On 04/07/2011 03:07 AM, Ali Çehreli wrote: Given an array of strings std.string.join() returns a single string: import std.string; void main() { string[] a1 = [hello, red]; string j1 = join(a1, ); // OK } But in a program I need an array of mutable arrays of chars. If I join the arrays I get a mutable array of chars. [...] Finally, casting ourselves works: string j2 = cast(string)join(a2, ); Oh, that's very good news! Thans Ali, I never thought at that solution. I'm often i/dup-ing from/to string to manipulate text due to the fact there is no automatic conversion. cast() works in place, doesn't it? so this is supposed avoid to avoid copy. PS: Checked: indeed, it works in-place. But watch the gotcha: unittest { string s = abc; char[] chars = cast(char[])s; chars ~= de; s = cast(string) chars; writeln(s, ' ', chars); // abcde abcde chars[1] = 'z'; writeln(s, ' ', chars); // azcde azcde } s's chars are mutable ;-) So, I guess there is /really/ no reason for implicite casts between char[] and string no to exist. (I assumed the reason was precisely to avoid such traps). Denis -- _ vita es estrany spir.wikidot.com
Re: char[][] join == string
On 04/07/2011 09:52 AM, spir wrote: On 04/07/2011 03:07 AM, Ali Çehreli wrote: Given an array of strings std.string.join() returns a single string: import std.string; void main() { string[] a1 = [hello, red]; string j1 = join(a1, ); // OK } But in a program I need an array of mutable arrays of chars. If I join the arrays I get a mutable array of chars. [...] Finally, casting ourselves works: string j2 = cast(string)join(a2, ); Oh, that's very good news! Thans Ali, I never thought at that solution. I'm often i/dup-ing from/to string to manipulate text due to the fact there is no automatic conversion. cast() works in place, doesn't it? so this is supposed avoid to avoid copy. PS: Checked: indeed, it works in-place. But watch the gotcha: unittest { string s = abc; char[] chars = cast(char[])s; chars ~= de; s = cast(string) chars; writeln(s, ' ', chars); // abcde abcde Sorry: forgot this line: assert(s.ptr == chars.ptr); // pass chars[1] = 'z'; writeln(s, ' ', chars); // azcde azcde } s's chars are mutable ;-) So, I guess there is /really/ no reason for implicite casts between char[] and string no to exist. (I assumed the reason was precisely to avoid such traps). Denis -- _ vita es estrany spir.wikidot.com
Re: char[][] join == string
On 04/07/2011 09:52 AM, spir wrote: On 04/07/2011 03:07 AM, Ali Çehreli wrote: Given an array of strings std.string.join() returns a single string: import std.string; void main() { string[] a1 = [hello, red]; string j1 = join(a1, ); // OK } But in a program I need an array of mutable arrays of chars. If I join the arrays I get a mutable array of chars. [...] Finally, casting ourselves works: string j2 = cast(string)join(a2, ); Oh, that's very good news! Thans Ali, I never thought at that solution. I'm often i/dup-ing from/to string to manipulate text due to the fact there is no automatic conversion. cast() works in place, doesn't it? so this is supposed avoid to avoid copy. PS: Checked: indeed, it works in-place. But watch the gotcha: unittest { string s = abc; char[] chars = cast(char[])s; chars ~= de; s = cast(string) chars; writeln(s, ' ', chars); // abcde abcde chars[1] = 'z'; writeln(s, ' ', chars); // azcde azcde } s's chars are mutable ;-) So, I guess there is /really/ no reason for implicite casts between char[] and string no to exist. (I assumed the reason was precisely to avoid such traps). After some more thought, I guess it's better to leave things as are. We have a way to cast without copy --which is one issue perfectly solved. The other issue --typing-- is small enough to keep it, since it also serves as warning to the programmer about the above trap. What should definitely be done is teaching this idiom in all relevant places of the reference, manuals, tutorials: while this issue is often submitted on D lists, I had never read about it (nore thought about it myself). Questions: did you know this idiom? if yes, have you found it yourself or read about it? if the latter, where? Denis -- _ vita es estrany spir.wikidot.com
ddoc patterns
Hello, In D stdlib's ddoc the idiom $(D some d code) is constantly used. But it does not work by me. Not only it's not interpreted, but the contents are stripped out all together. (A *very* big bug of ddoc.) First, I'd like to know why. Second, there is another pattern $(D_CODE some d code), but it place the code on a separate block. Is this intended? Third, http://www.digitalmars.com/d/2.0/ddoc.html seems to imply one can define new patterns. How to do that? I tried following the example, but my code ends up interpreted and stripped out. Denis -- _ vita es estrany spir.wikidot.com
D programs linked with C/MPI based libraries
Hello, Is it possible to call within a D driver program library functions which are programmed in C/C++ with the message passing interface (MPI)? I want to write a program which makes use of the ParMetis library (http://glaros.dtc.umn.edu/gkhome/metis/parmetis/overview). Supposing it is possible, to compile and run C/MPI programs, wrapper commands are used, such as mpicc and mpirun. What would be done in D? Thank you, Dominic Jones
Re: ddoc patterns
On 04/07/2011 10:20 AM, spir wrote: Hello, In D stdlib's ddoc the idiom $(D some d code) is constantly used. But it does not work by me. Not only it's not interpreted, but the contents are stripped out all together. (A *very* big bug of ddoc.) First, I'd like to know why. Second, there is another pattern $(D_CODE some d code), but it place the code on a separate block. Is this intended? Third, http://www.digitalmars.com/d/2.0/ddoc.html seems to imply one can define new patterns. How to do that? I tried following the example, but my code ends up interpreted and stripped out. OK found it: pattern defs must be places under a Macro: section title. I take the opprtunity to ask another question: does anyone know how to tag a *span* of text as literal/uninterpreted (either in html or css). The issue is pre makes a *block*, even if not inside a div or p; I desperately need the same feature for inline pieces of code. Denis -- _ vita es estrany spir.wikidot.com
Re: null Vs [] return arrays
On Tue, 05 Apr 2011 18:46:06 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: On Tue, 05 Apr 2011 13:24:49 -0400, Regan Heath re...@netmail.co.nz wrote: On Fri, 01 Apr 2011 18:23:28 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: assert( !is null); // works on D. Try it. Yes, but that's because this is a string literal. It's not useful where you're getting your input from somewhere else.. like in the other 2 use cases I mentioned. But that isn't the same as []. Basically, if you have an existing array, and you want to create a non-null empty array out of it, a slice of [0..0] always works. I know you mention it, but I want to draw attention to the original problem, that [] returns a null array. Other cases where you are not using [] or are a separate issue. All the cases you have brought up involve strings, for which there is a non-null array returned for . I still have not yet seen a compelling use case for making [] return non-null. Ahh.. I see, I really should have renamed the thread title. I'm not, and never was, arguing for [] (specifically) returning non-null. Sorry. Quoting from your message previously (with added comment): case 4: return cast(char[]).dup; case 5: return cast(char[])[0..0]; // note lack of .dup } Drat, not sure what happened there. My source had the 'dup' when I went back to it. Sorry. -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Re: ddoc patterns
spir: I take the opprtunity to ask another question: does anyone know how to tag a *span* of text as literal/uninterpreted (either in html or css). The issue is pre makes a *block*, even if not inside a div or p; I desperately need the same feature for inline pieces of code. Try: -- code here -- Bye, bearophile
Re: [SOLVED] [BUG?] Re: error Not the start of the UTF-8 sequence
spir Wrote: I get this error message: Not the start of the UTF-8 sequence if it's '\0', the error message is clearly incorrect, report a bug.
Re: null Vs [] return arrays
bearophile Wrote: Regan Heath: conceptually it's nice to be able to express (exists but is empty) and (does not exist). You may want to express that, but for the implementation of the language those two situations are the same, because in the [] literal the ptr is null. So I think it's better for the programmer to not differentiate the two situations, because they are not different. If the programmer tells them apart, he/she is doing something bad in D, creating a false illusion. It's bad, when the language is driven by the implementation of a reference compiler by the copyright holder. This way compiler bugs and tricks become a language standard. See the story of VP7 codec.
Re: ddoc patterns
On 04/07/2011 12:53 PM, bearophile wrote: spir: I take the opprtunity to ask another question: does anyone know how to tag a *span* of text as literal/uninterpreted (either in html or css). The issue is pre makes a *block*, even if not inside adiv orp; I desperately need the same feature for inline pieces of code. Try: -- code here -- Bye, bearophile This makes a block --just what I don't want. Denis -- _ vita es estrany spir.wikidot.com
Re: ddoc patterns
On 2011-04-07 12:25, spir wrote: On 04/07/2011 10:20 AM, spir wrote: Hello, In D stdlib's ddoc the idiom $(D some d code) is constantly used. But it does not work by me. Not only it's not interpreted, but the contents are stripped out all together. (A *very* big bug of ddoc.) First, I'd like to know why. Second, there is another pattern $(D_CODE some d code), but it place the code on a separate block. Is this intended? Third, http://www.digitalmars.com/d/2.0/ddoc.html seems to imply one can define new patterns. How to do that? I tried following the example, but my code ends up interpreted and stripped out. OK found it: pattern defs must be places under a Macro: section title. I take the opprtunity to ask another question: does anyone know how to tag a *span* of text as literal/uninterpreted (either in html or css). The issue is pre makes a *block*, even if not inside a div or p; I desperately need the same feature for inline pieces of code. Denis Have a look at the CSS display property: http://w3schools.com/css/pr_class_display.asp -- /Jacob Carlborg
Re: incompatible types!
On Wed, 06 Apr 2011 12:32:37 -0400, simendsjo simen.end...@pandavre.com wrote: Both the d1 and d2 homepage states the following: There are two versions of the language: 1. D version 1 which is in maintenance mode. 2. D version 2 which is recommended for new projects. Should it mention that d2 is beta and phobos alpha? Or are you alone in thinking that? I would recommend that it said this. Maybe I'm alone, and everyone else has no issues when they use D2. It's not up to me what to say on digitalmars, I am not in charge of that page. BTW, if it's a choice between D1/phobos and D2/phobos, I highly recommend D2/phobos. D1 phobos is woefully inadequate for any real projects (when I first learned D it was for a networking project at work, and I tried D1/phobos for about a week before looking for something better), I recommend D1/tango if you want to use D1. -Steve
Re: Strange bug in std.concurrency.spawn
On Tue, 05 Apr 2011 01:19:08 -0300, Jose Armando Garcia wrote: 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. Is this a bug in spawn(), a bug in dmd or a limitation of the language? * If it is a bug in spawn, how can it be augmented to check this case? * If this is a bug in dmd, I'll file a report. * If this is a limitation of the language is this well known and it is worked on? As it stands it doesn't seem possible to write safe multi-threaded code. It's not a language limitation. The signature is: Tid spawn(T...)( void function(T) fn, T args ); So the compiler should ensure that fn(args) is typesafe. Please search bugzilla for this bug and report it if not found.
Re: char[][] join == string
On Thu, 07 Apr 2011 02:13:16 +0200, bearophile bearophileh...@lycos.com wrote: Given an array of strings std.string.join() returns a single string: import std.string; void main() { string[] a1 = [hello, red]; string j1 = join(a1, ); // OK } But in a program I need an array of mutable arrays of chars. If I join the arrays I get a mutable array of chars. But I need a string: import std.string; void main() { char[][] a2 = [hello.dup, red.dup]; string j2 = join(a2, ); // error } Error: cannot implicitly convert expression (join(a, )) of type char[] to string .idup avoids the error: string j3 = join(a2, ).idup; // OK Given the low efficiency of the D GC it's better to reduce memory allocations as much as possible. Here join() creates a brand new array, so idup performs a useless copy. To avoid this extra copy do I have to write another joinString() function? Bye, bearophile Isn't this a prime case for std.exception.assumeUnique? -- Simen
use of C memmove
Hello, I'm trying to use C's memmove as a tool to delete or insert a slice from/into an array. But I cannot manage to do it: systematic segmentation fault. What is wrong below? import std.c.string : memmove; // void *memmove(void *dest, const void *src, size_t n); void moveEnd (E) (E[] elements, size_t start, int offset) { // Length must be known before possible extension. auto length = elements.length; // If move up, extend array to make place. if (offset 0) elements.length += offset; // Move slice. auto dest = cast(void*)((elements[start + offset])); auto source = cast(void*)((elements[start])); size_t size = length - start; memmove(dest, source, size);// segfault *** // If move down, compress array. if (offset 0) elements.length += offset; } unittest { string s = 012--3456789; // Remove slice. s.moveEnd(5, -2); writeln(s); } Denis -- _ vita es estrany spir.wikidot.com
Re: ddoc patterns
On 04/07/2011 03:32 PM, Jacob Carlborg wrote: On 2011-04-07 12:25, spir wrote: On 04/07/2011 10:20 AM, spir wrote: Hello, In D stdlib's ddoc the idiom $(D some d code) is constantly used. But it does not work by me. Not only it's not interpreted, but the contents are stripped out all together. (A *very* big bug of ddoc.) First, I'd like to know why. Second, there is another pattern $(D_CODE some d code), but it place the code on a separate block. Is this intended? Third, http://www.digitalmars.com/d/2.0/ddoc.html seems to imply one can define new patterns. How to do that? I tried following the example, but my code ends up interpreted and stripped out. OK found it: pattern defs must be places under a Macro: section title. I take the opprtunity to ask another question: does anyone know how to tag a *span* of text as literal/uninterpreted (either in html or css). The issue is pre makes a *block*, even if not inside a div or p; I desperately need the same feature for inline pieces of code. Denis Have a look at the CSS display property: http://w3schools.com/css/pr_class_display.asp Great, does the trick! But is there else really no other way to suspend interpretation as pre? I find this strange... how are we supposed to insert code phrases in the flow of normal text? Denis -- _ vita es estrany spir.wikidot.com
Re: use of C memmove
On Thu, 07 Apr 2011 13:09:05 -0400, spir denis.s...@gmail.com wrote: Hello, I'm trying to use C's memmove as a tool to delete or insert a slice from/into an array. But I cannot manage to do it: systematic segmentation fault. What is wrong below? import std.c.string : memmove; // void *memmove(void *dest, const void *src, size_t n); void moveEnd (E) (E[] elements, size_t start, int offset) { // Length must be known before possible extension. auto length = elements.length; // If move up, extend array to make place. if (offset 0) elements.length += offset; // Move slice. auto dest = cast(void*)((elements[start + offset])); auto source = cast(void*)((elements[start])); size_t size = length - start; memmove(dest, source, size);// segfault *** // If move down, compress array. if (offset 0) elements.length += offset; } unittest { string s = 012--3456789; // Remove slice. s.moveEnd(5, -2); writeln(s); } Two problems. One is, the memmove size_t n is number of *bytes*, not number of elements as you have expected. You probably would have noticed this quickly if the other problem wasn't there. The other problem is, strings literals are immutable. On Windows, this code may have worked, but Linux protects the pages of static data, so writing to a string literal creates a seg fault. Try this: auto s = 012--3456789.dup; // convert to char[] To fix first problem use memmove(dest, source, size * (E).sizeof); -Steve
Re: char[][] join == string
On 04/07/2011 01:04 AM, spir wrote: On 04/07/2011 09:52 AM, spir wrote: On 04/07/2011 03:07 AM, Ali Çehreli wrote: Given an array of strings std.string.join() returns a single string: import std.string; void main() { string[] a1 = [hello, red]; string j1 = join(a1, ); // OK } But in a program I need an array of mutable arrays of chars. If I join the arrays I get a mutable array of chars. [...] Finally, casting ourselves works: string j2 = cast(string)join(a2, ); Questions: did you know this idiom? if yes, have you found it yourself or read about it? if the latter, where? I had heard about assumeUnique() a couple of times in these forums. I remember looking at its implementation. Ali
Re: D programs linked with C/MPI based libraries
Dominic Jones Wrote: Hello, Is it possible to call within a D driver program library functions which are programmed in C/C++ with the message passing interface (MPI)? I want to write a program which makes use of the ParMetis library (http://glaros.dtc.umn.edu/gkhome/metis/parmetis/overview). Supposing it is possible, to compile and run C/MPI programs, wrapper commands are used, such as mpicc and mpirun. What would be done in D? Looks like MPI is just another C interface. You just need to write binding for it and call it.
Re: use of C memmove
spir Wrote: // If move down, compress array. if (offset 0) elements.length += offset; ow, addAssign works on length?
Re: use of C memmove
On Thu, 07 Apr 2011 14:44:28 -0400, Kagamin s...@here.lot wrote: spir Wrote: // If move down, compress array. if (offset 0) elements.length += offset; ow, addAssign works on length? Since 12/09 :) http://www.digitalmars.com/d/2.0/changelog.html#new2_037 -Steve
Re: char[][] join == string
spir Wrote: unittest { string s = abc; char[] chars = cast(char[])s; chars ~= de; s = cast(string) chars; writeln(s, ' ', chars); // abcde abcde chars[1] = 'z'; writeln(s, ' ', chars); // azcde azcde } s's chars are mutable ;-) So, I guess there is /really/ no reason for implicite casts between char[] and string no to exist. (I assumed the reason was precisely to avoid such traps). After some more thought, I guess it's better to leave things as are. We have a way to cast without copy --which is one issue perfectly solved. The other issue --typing-- is small enough to keep it, since it also serves as warning to the programmer about the above trap. What should definitely be done is teaching this idiom in all relevant places of the reference, manuals, tutorials: while this issue is often submitted on D lists, I had never read about it (nore thought about it myself). Questions: did you know this idiom? if yes, have you found it yourself or read about it? if the latter, where? Casting to and from string/char[] is very dangerous, even through assumeUnique. AssumeUnique is intended to be used for returning a mutable as immutable from a function. Casting is often a no-op for the CPU and as you discovered removes any safety provided by the type system. While modifying immutable data is undefined, if you can guarantee the data truly is mutable and the compiler won't be optimizing with the assumption of immutability, it is perfectly safe. It is just in the hands of the programmer now.
Adding days to std.datetime.Date
Is it possible to add a particular number of days to a Date? I have number of days since 1 Jan 2000 and I want to convert it to Date: int days = read!int; // number of days since 1 Jan 2000 Date x = Date(2000, 1, 1); x.add!days(days); Unfortunately add() does not support adding days. Will it be possible in the future or is there another approach? Thanks
Re: use of C memmove
On 04/07/2011 08:12 PM, Steven Schveighoffer wrote: On Thu, 07 Apr 2011 13:09:05 -0400, spir denis.s...@gmail.com wrote: Hello, I'm trying to use C's memmove as a tool to delete or insert a slice from/into an array. But I cannot manage to do it: systematic segmentation fault. What is wrong below? import std.c.string : memmove; // void *memmove(void *dest, const void *src, size_t n); void moveEnd (E) (E[] elements, size_t start, int offset) { // Length must be known before possible extension. auto length = elements.length; // If move up, extend array to make place. if (offset 0) elements.length += offset; // Move slice. auto dest = cast(void*)((elements[start + offset])); auto source = cast(void*)((elements[start])); size_t size = length - start; memmove(dest, source, size); // segfault *** // If move down, compress array. if (offset 0) elements.length += offset; } unittest { string s = 012--3456789; // Remove slice. s.moveEnd(5, -2); writeln(s); } Two problems. One is, the memmove size_t n is number of *bytes*, not number of elements as you have expected. You probably would have noticed this quickly if the other problem wasn't there. The other problem is, strings literals are immutable. On Windows, this code may have worked, but Linux protects the pages of static data, so writing to a string literal creates a seg fault. Try this: auto s = 012--3456789.dup; // convert to char[] To fix first problem use memmove(dest, source, size * (E).sizeof); Thank you very much, Steven! Denis -- _ vita es estrany spir.wikidot.com
Re: assumeSafeAppend inconsistent when multiple slices in use
On 05.04.2011 22:04, Steven Schveighoffer wrote: On Tue, 05 Apr 2011 15:24:46 -0400, simendsjo simen.end...@pandavre.com wrote: I don't know if this is an actual problem, but I don't understand the behavior. When one slice calls assumeSafeAppend, both slices is given control, that is, gets the parents capacity. You have to stop thinking of array slices as unique :) Ok, done. If you look at the dissection of a slice, it is a pointer and length. That is all. So if b.ptr == c.ptr b.length == c.length, then both slices not only are the same, but are identical. That is, the runtime cannot tell the difference. It might be easier to think about it this way. First, there are no arrays in the traditional definition, only slices. Every array slice which references the heap is backed by a memory block. The block has a fixed size (e.g. 16 bytes, 32 bytes, 64 bytes, etc.). However, encoded in the block itself is the 'used length', which is basically the number of bytes in the block which are actually being used. If you took a slice of the block from the beginning of the block and with length equivalent to the 'used length', we can call this the 'master slice'. The array appending code allows appending ONLY when the slice being appended ends at the same point that the master slice ends (and when there is space available). all assumeSafeAppend does is adjust that used length so it ends at the same point as the given slice. So it's not actually blessing anything about the specific slice you use to call it with, it's just adjusting the 'master slice' to make it so the array you give will be appendable. (snip) If I have thoroughly confused you now, please ask more questions :) A very thorough explanation which changes my view of arrays. I thought slices, array stomping protection and reallocation had very complicated rules (and perhaps it has under the hood..?) I tried to look at assumeSafeAppend's code, and although I didn't understand everything, I think that together with your great explanation I got it, but lets see... I'm having some problems explaining it as I'm not sure about the correct terminology (I should have drawn some pictures..), but I'll try. The runtime doesn't track the original array and the slices (for this example at least - it obviously do for the sake of gc). Internally it keeps an address to the current endpoint in the chunk of memory like array.ptr+array.length. Any array that ends on this address is allowed to append fill the memory without reallocating as it points to the end of the array. But whenever a slice that's allowed to append/change length changes, it will change the endpoint address for the chunk of memory, and thus the other slices probably points at an earlier element and cannot append. Any element not pointing at the endpoint will return capacity==0. There is one thing I don't understand though.. However, a does not end on the master slice, so its capacity is 0. Note that technically using a[1..$] is undefined at this point since the runtime considers those elements 'unused'. What do you mean be undefined in this context? Do you mean because it can be overwritten like this? int[] a = [1,2]; int[] b = a[0..1]; b.assumeSafeAppend(); b.length += 1; assert(a == [1,0]); // a[1] overwritten as int.init is called on the element Or is it because it's outside what the runtime considers part of the used array and is free to do what it want's with it? Or doesn't the gc track slices with an endpoint greater than the current endpoint so it might return memory to the OS?
Re: D programs linked with C/MPI based libraries
Dominic Jones Wrote: Hello, Is it possible to call within a D driver program library functions which are programmed in C/C++ with the message passing interface (MPI)? I want to write a program which makes use of the ParMetis library (http://glaros.dtc.umn.edu/gkhome/metis/parmetis/overview). Supposing it is possible, to compile and run C/MPI programs, wrapper commands are used, such as mpicc and mpirun. What would be done in D? Thank you, Dominic Jones It is possible and I suppose everything not passing and retrieving messages would be done in D. There is probably a bunch of work involved in converting the headers, but there isn't any reason D can't call into MPI.
Re: Adding days to std.datetime.Date
On Thu, 07 Apr 2011 15:07:02 -0400, Piotr Szturmaj bncr...@jadamspam.pl wrote: Is it possible to add a particular number of days to a Date? I have number of days since 1 Jan 2000 and I want to convert it to Date: int days = read!int; // number of days since 1 Jan 2000 Date x = Date(2000, 1, 1); x.add!days(days); Unfortunately add() does not support adding days. Will it be possible in the future or is there another approach? Yes, use core.time.Duration. Duration was moved to core so it could be used in core functions, like Thread.sleep. so x += dur!days(days); See: http://www.digitalmars.com/d/2.0/phobos/core_time.html#dur -Steve
Re: assumeSafeAppend inconsistent when multiple slices in use
On Thu, 07 Apr 2011 15:22:10 -0400, simendsjo simen.end...@pandavre.com wrote: On 05.04.2011 22:04, Steven Schveighoffer wrote: However, a does not end on the master slice, so its capacity is 0. Note that technically using a[1..$] is undefined at this point since the runtime considers those elements 'unused'. What do you mean be undefined in this context? Do you mean because it can be overwritten like this? int[] a = [1,2]; int[] b = a[0..1]; b.assumeSafeAppend(); b.length += 1; assert(a == [1,0]); // a[1] overwritten as int.init is called on the element yes, although the above does not represent technically undefined behavior -- you didn't access a[1] when a[1] was not considered part of the used space. Or is it because it's outside what the runtime considers part of the used array and is free to do what it want's with it? Yes on this count too. For example, it might be that some runtime implementations, when you call assumeSafeAppend, could write 0xdeadbeef into the elements that are no-longer valid. This is perfectly acceptable, and as long as you don't access those elements, the behavior should be predictable. I'm not a language lawyer, so maybe the better term is 'implementation defined'. I'm not sure. Or doesn't the gc track slices with an endpoint greater than the current endpoint so it might return memory to the OS? The GC does not partially deallocate a block. These slices will still point to the block, so it won't be collected. Note that the GC proper does not really know about the used length. It just knows that there is an allocated block of size X. Only the runtime knows what data is 'used' and what is 'free' inside the block (specifically the array management part of the runtime). -Steve
Re: assumeSafeAppend inconsistent when multiple slices in use
On Thu, 07 Apr 2011 15:22:10 -0400, simendsjo simen.end...@pandavre.com wrote: I'm having some problems explaining it as I'm not sure about the correct terminology (I should have drawn some pictures..), but I'll try. The runtime doesn't track the original array and the slices (for this example at least - it obviously do for the sake of gc). Internally it keeps an address to the current endpoint in the chunk of memory like array.ptr+array.length. Any array that ends on this address is allowed to append fill the memory without reallocating as it points to the end of the array. But whenever a slice that's allowed to append/change length changes, it will change the endpoint address for the chunk of memory, and thus the other slices probably points at an earlier element and cannot append. Any element not pointing at the endpoint will return capacity==0. This all looks correct. -Steve
Re: Adding days to std.datetime.Date
Steven Schveighoffer wrote: On Thu, 07 Apr 2011 15:07:02 -0400, Piotr Szturmaj bncr...@jadamspam.pl wrote: Is it possible to add a particular number of days to a Date? I have number of days since 1 Jan 2000 and I want to convert it to Date: int days = read!int; // number of days since 1 Jan 2000 Date x = Date(2000, 1, 1); x.add!days(days); Unfortunately add() does not support adding days. Will it be possible in the future or is there another approach? Yes, use core.time.Duration. Duration was moved to core so it could be used in core functions, like Thread.sleep. so x += dur!days(days); See: http://www.digitalmars.com/d/2.0/phobos/core_time.html#dur Well, I did find it few mins ago. But std.datetime's doc still states that it provide types to represent durations of time. -Steve Thanks!
Re: char[][] join == string
Jesse Phillips: Casting to and from string/char[] is very dangerous, even through assumeUnique. AssumeUnique is intended to be used for returning a mutable as immutable from a function. Casting is often a no-op for the CPU and as you discovered removes any safety provided by the type system. A more expressive type system (uniqueness annotations, lending, linear types) allows to write that code in a safe way, but introduces some new complexities too. The GHC Haskell compiler has some experimental extensions (mostly to its type system) disabled on default (you need to add an annotation in your programs to switch each extension on), to experiment and debug/engineer ideas like that. I presume Walter is too much busy to do this in D, but I'd like something similar. On the other hand we'll probably have a Phobos package for experimental standard modules. Bye, bearophile
How to handle assert() in Windows GUI apps?
It turns out that using assert() that throws in a Windows application will show an error such as this: --- first.exe - Application Error --- The instruction at 0x00411e6a referenced memory at 0x0044. The memory could not be read. --- I'm not sure if this is a bug or expected behavior. If it's expected, isn't it possible to reroute assert() to use a dialog box and report the failed assert there? Here's the code, using WindowsAPI from dsource, non-unicode mode: http://codepad.org/LOvfAwSR
Re: How to handle assert() in Windows GUI apps?
Oh I'm so stupid I didn't realize my commands were outside the try catch statement.
Re: How to handle assert() in Windows GUI apps?
Everything works fine now, please disregard my silly thread. :)
Compiling DMD
Is the makefile supposed to work out-of-the-box, or is it expected that it be edited first? Because when I do make -f win32.mak form the src dir I just get Error: '\dm\bin\dmc' not found. Same (exact same) result if I do make -f win32.mak D=path_to_parent_of_dm. I know I can just hack the make file to make it work like I've alwayd done before, but now that I'm starting to work with the source from github, I want to see if theres a proper way to do it that I'm missing that won't end up with me needing to omit the makefile from commits and re-apply my change whenever I pull a new version of the makefile.
How to run DMD's tests?
Like the subject says. I try to use the makefile, but I keep getting this: Error on line 76: expecting target : dependencies