Re: dChar Error
On 30/12/2022 6:37 PM, Salih Dincer wrote: On Friday, 30 December 2022 at 04:54:39 UTC, Richard (Rikki) Andrew Cattermole wrote: So when you duplicated it, it was no longer in ROM, and therefore writable. There is no such thing as a ROM within a function. But a function can reference things in ROM, and a function itself can and should be held within ROM. Because str is a reference and slc is a local copy, right? It is a reference to memory that is in ROM. No, it is not a copy of the memory, only of the reference. You shouldn't be casting away immutable btw, (which is what string is!). Have you tried running the code? Okay, no string literals: Of course; I cannot see anything else that could cause this in the assembly either.
Re: dChar Error
On Friday, 30 December 2022 at 04:54:39 UTC, Richard (Rikki) Andrew Cattermole wrote: So when you duplicated it, it was no longer in ROM, and therefore writable. There is no such thing as a ROM within a function. Because str is a reference and slc is a local copy, right? Have you tried running the code? Okay, no string literals: ```d void main() { // example one: char[] str1 = "cur:€_".dup; str1.length.write(": "); // 8: str1[4..$].writefln!"[%s]"; // [€_] char[] slc1 = "$ _".dup; str1.replaceRight(slc1); str1.writefln!"[%s]"; // [cur:$ _] // example two: dchar[] str2 = cast(dchar[])"cur:€_"d; str2.length.write(": "); // 6: str2[4..$].writefln!"[%s]"; // [€_] dchar[] slc2 = cast(dchar[])"$ _"d; str2.replaceRight(slc2); str2.writefln!"[%s]"; } ``` SDB@79
Re: dChar Error
Because, string literals are in Read Only Memory (or should be anyway). If you write to ROM, it'll of course error by the CPU. So when you duplicated it, it was no longer in ROM, and therefore writable.
dChar Error
Hi All, What is causing the error in the code snippet below? ```d void replaceRight(S)(ref S[] str, S[] slc) { size_t len1 = slc.length, len2 = str[len1..$].length; assert(len1 == len2); str[len1..$] = slc; } import std.stdio; void main() { // example one: char[] str1 = "cur:€_".dup; str1.length.write(": "); // 8: str1[4..$].writefln!"[%s]"; // [€_] str1.replaceRight("$ _".dup); str1.writefln!"[%s]"; // [cur:$ _] // example two: dchar[] str2 = cast(dchar[])"cur:€_"d; str2.length.write(": "); // 6: str2[4..$].writefln!"[%s]"; // [€_] str2.replaceRight(cast(dchar[])"$ _"d); str2.writefln!"[%s]"; // Error--^ } /* Prints: 8: [€_] [cur:$ _] 6: [€_] Error: program killed by signal 11 */ ``` Why does replaceRight() work fine with a char array, but not a dchar array? Whereas, rvalue and lvalue lengths are equal to each other! SDB@79
Re: How Can i see associative array implement , is where has pseudocode write in Dlang?
On Thursday, 29 December 2022 at 11:24:38 UTC, lil wrote: How Can i see associative array implement , is where has pseudocode write in Dlang? If you're asking for the implementation of Associative Arrays, you can find that in druntime in the `rt.aaA` module: https://github.com/dlang/dmd/blob/master/druntime/src/rt/aaA.d There's no pseudo code of it, but it's a pretty standard hash table.
Re: How Can i see associative array implement , is where has pseudocode write in Dlang?
On Thursday, 29 December 2022 at 11:24:38 UTC, lil wrote: How Can i see associative array implement , is where has pseudocode write in Dlang? Maybe this will help: https://github.com/dlang/phobos/blob/master/std/array.d Matheus.
How Can i see associative array implement , is where has pseudocode write in Dlang?
How Can i see associative array implement , is where has pseudocode write in Dlang?