Re: Removing an element from a DList
On Tuesday, 17 October 2023 at 17:27:19 UTC, Joakim G. wrote: For some reason I cannot remove an element from a DList. I tried several range approaches but to no avail. I'm a noob. In the end I did this: ``` private void removeFromWaitingQueue(uint jid) { auto arr = waitingQueue[].array; arr = arr.remove!(job => job.jid == jid); waitingQueue.clear(); foreach(job; arr) { waitingQueue.insertBack(job); } } ``` Any hints? /J "ranges are views of data" blah blah blah that remove function returns a fancy pointer and is lazy not the sane eager "unsafe" thing, the std avoids mutation to an unhelpful degree also std.containeers is awful Id suggest using dynamic arrays swapping the last element to index then length--; or nullable static arrays; or just using filter if a functional approach is on the table.
Removing an element from a DList
For some reason I cannot remove an element from a DList. I tried several range approaches but to no avail. I'm a noob. In the end I did this: ``` private void removeFromWaitingQueue(uint jid) { auto arr = waitingQueue[].array; arr = arr.remove!(job => job.jid == jid); waitingQueue.clear(); foreach(job; arr) { waitingQueue.insertBack(job); } } ``` Any hints? /J
Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?
On Tuesday, 17 October 2023 at 13:31:39 UTC, Salih Dincer wrote: On Sunday, 15 October 2023 at 07:22:53 UTC, Imperatorn wrote: You already got a lot of good answers, I thought I'd just share this for anyone searching for nogc string formatting compatible with betterC: https://code.dlang.org/packages/bc-string Doesn't it make more sense to use [ParseResult!T parse(T)(cstring str)](https://github.com/tchaloupka/bc-string/blob/master/source/bc/string/conv.d) instead of nested if's here: https://github.com/tchaloupka/bc-string/blob/master/source/bc/string/numeric.d Thanks, SDB@79 Omg, yeah, that looks like some kind of hack. Make a PR :)
Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?
On Sunday, 15 October 2023 at 07:22:53 UTC, Imperatorn wrote: You already got a lot of good answers, I thought I'd just share this for anyone searching for nogc string formatting compatible with betterC: https://code.dlang.org/packages/bc-string Doesn't it make more sense to use [ParseResult!T parse(T)(cstring str)](https://github.com/tchaloupka/bc-string/blob/master/source/bc/string/conv.d) instead of nested if's here: https://github.com/tchaloupka/bc-string/blob/master/source/bc/string/numeric.d Thanks, SDB@79
Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?
On Sunday, 15 October 2023 at 07:22:53 UTC, Imperatorn wrote: You already got a lot of good answers, I thought I'd just share this for anyone searching for nogc string formatting compatible with betterC: https://code.dlang.org/packages/bc-string You thought, well, thank you very much and have a great day!
Re: std.format with named args
On Tuesday, 17 October 2023 at 07:53:28 UTC, Vitaliy Fadeev wrote: On Tuesday, 17 October 2023 at 07:22:41 UTC, Vitaliy Fadeev wrote: [...] `scriptlike` looks perfecto! ```D enum JMP_ADDR_R = ... ... import scriptlike; writeln( mixin(interp!" asm { lea ${JMP_ADDR_R}, qword ptr [ ${JMP_I_R} * ${PTR_SIZE} + ${TBL_ADDR} ]; jmp [${JMP_ADDR_R}]; } ") ); ``` produced: ``` asm { lea RAX, qword ptr [ RDX * 8 + 5594AA134290 ]; jmp [RAX]; } ``` Closed! `scriptlike` Thanks, all! Nice
Re: std.format with named args
On Tuesday, 17 October 2023 at 07:22:41 UTC, Vitaliy Fadeev wrote: On Tuesday, 17 October 2023 at 06:57:07 UTC, Imperatorn wrote: On Tuesday, 17 October 2023 at 06:46:31 UTC, Vitaliy Fadeev wrote: Hi all! I want readable mixin. I want pass variable to string. I want string with named args. Like this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [JMP_ADDR_R]; }"( JMP_ADDR_R ));// IT NOT WORK ``` Not this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [%s]; }"( JMP_ADDR_R ));// WORK, BUT NOT-READABLE ``` In large code named identifiers more readable. In future it will used in jump table, like this: ```D mixin( format!"asm { lea JMP_ADDR_R, qword ptr [ JMP_I_R * PTR_SIZE + TBL_ADDR ]; jmp [JMP_ADDR_R]; }"( JMP_I_R, PTR_SIZE, TBL_ADDR, JMP_ADDR_R )); ``` Please, help me find a solution... or exists std.format with named args ? or another solution with named args ? Without string interpolation the best you can do is https://dlang.org/library/std/conv/text.html Or write some code yourself, unfortunately May be. "String interpolation" ```D mixin( format!"asm { lea JMP_ADDR_R, qword ptr [ JMP_I_R * PTR_SIZE + TBL_ADDR ]; jmp [JMP_ADDR_R]; }"( JMP_I_R, PTR_SIZE, TBL_ADDR, JMP_ADDR_R )); ``` vs text() ```D mixin( text( "asm { lea", JMP_ADDR_R, ", qword ptr [ ", JMP_I_R, " * ", PTR_SIZE, " + ", TBL_ADDR, " ]; jmp [", JMP_ADDR_R, "]; }")); ``` "String interpolation" more readable. "String interpolation" easier to type. "text()" syntax is highlighted, Thanks for the correct keywords: "String interpolation" - this is what I'm looking for. Is there a "string interpolation" solution? `scriptlike` looks perfecto! ```D enum JMP_ADDR_R = ... ... import scriptlike; writeln( mixin(interp!" asm { lea ${JMP_ADDR_R}, qword ptr [ ${JMP_I_R} * ${PTR_SIZE} + ${TBL_ADDR} ]; jmp [${JMP_ADDR_R}]; } ") ); ``` produced: ``` asm { lea RAX, qword ptr [ RDX * 8 + 5594AA134290 ]; jmp [RAX]; } ``` Closed! `scriptlike` Thanks, all!
Re: std.format with named args
On Tuesday, 17 October 2023 at 06:57:07 UTC, Imperatorn wrote: On Tuesday, 17 October 2023 at 06:46:31 UTC, Vitaliy Fadeev wrote: Hi all! I want readable mixin. I want pass variable to string. I want string with named args. Like this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [JMP_ADDR_R]; }"( JMP_ADDR_R ));// IT NOT WORK ``` Not this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [%s]; }"( JMP_ADDR_R ));// WORK, BUT NOT-READABLE ``` In large code named identifiers more readable. In future it will used in jump table, like this: ```D mixin( format!"asm { lea JMP_ADDR_R, qword ptr [ JMP_I_R * PTR_SIZE + TBL_ADDR ]; jmp [JMP_ADDR_R]; }"( JMP_I_R, PTR_SIZE, TBL_ADDR, JMP_ADDR_R )); ``` Please, help me find a solution... or exists std.format with named args ? or another solution with named args ? Without string interpolation the best you can do is https://dlang.org/library/std/conv/text.html Or write some code yourself, unfortunately May be. "String interpolation" ```D mixin( format!"asm { lea JMP_ADDR_R, qword ptr [ JMP_I_R * PTR_SIZE + TBL_ADDR ]; jmp [JMP_ADDR_R]; }"( JMP_I_R, PTR_SIZE, TBL_ADDR, JMP_ADDR_R )); ``` vs text() ```D mixin( text( "asm { lea", JMP_ADDR_R, ", qword ptr [ ", JMP_I_R, " * ", PTR_SIZE, " + ", TBL_ADDR, " ]; jmp [", JMP_ADDR_R, "]; }")); ``` "String interpolation" more readable. "String interpolation" easier to type. "text()" syntax is highlighted, Thanks for the correct keywords: "String interpolation" - this is what I'm looking for. Is there a "string interpolation" solution?
Re: std.format with named args
On Tuesday, 17 October 2023 at 06:46:31 UTC, Vitaliy Fadeev wrote: Hi all! I want readable mixin. I want pass variable to string. I want string with named args. Like this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [JMP_ADDR_R]; }"( JMP_ADDR_R ));// IT NOT WORK ``` Not this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [%s]; }"( JMP_ADDR_R ));// WORK, BUT NOT-READABLE ``` In large code named identifiers more readable. In future it will used in jump table, like this: ```D mixin( format!"asm { lea JMP_ADDR_R, qword ptr [ JMP_I_R * PTR_SIZE + TBL_ADDR ]; jmp [JMP_ADDR_R]; }"( JMP_I_R, PTR_SIZE, TBL_ADDR, JMP_ADDR_R )); ``` Please, help me find a solution... or exists std.format with named args ? or another solution with named args ? Without string interpolation the best you can do is https://dlang.org/library/std/conv/text.html Or write some code yourself, unfortunately
std.format with named args
Hi all! I want readable mixin. I want pass variable to string. I want string with named args. Like this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [JMP_ADDR_R]; }"( JMP_ADDR_R ));// IT NOT WORK ``` Not this: ```D enum JMP_ADDR_R = "RAX"; mixin( format!"asm { jmp [%s]; }"( JMP_ADDR_R ));// WORK, BUT NOT-READABLE ``` In large code named identifiers more readable. In future it will used in jump table, like this: ```D mixin( format!"asm { lea JMP_ADDR_R, qword ptr [ JMP_I_R * PTR_SIZE + TBL_ADDR ]; jmp [JMP_ADDR_R]; }"( JMP_I_R, PTR_SIZE, TBL_ADDR, JMP_ADDR_R )); ``` Please, help me find a solution... or exists std.format with named args ? or another solution with named args ?