Re: How to get output of piped process?

2021-02-18 Thread frame via Digitalmars-d-learn
On Thursday, 18 February 2021 at 17:27:48 UTC, Steven Schveighoffer wrote: readln will block. eof doesn't tell you that there is no data in the pipe, it just says whether the pipe has been closed. Of course, I must have been thinking of another language - I should take a coffee before postin

Re: How do I enable visual styles?

2021-02-18 Thread Jack via Digitalmars-d-learn
if someone happens to be looking to do that in the future: I didn't find a way to do this with a linker but managed to find a way to do this with code only. The code goes like this: // source: https://stackoverflow.com/a/10444161/800123 #include // NOTE: It is recommended that you delay-load

Re: Trying to reduce memory usage

2021-02-18 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 04:10:24 UTC, tsbockman wrote: I spent some time experimenting with this problem, and here is the best solution I found, assuming that perfect de-duplication is required. (I'll put the code up on GitHub / dub if anyone wants to have a look.) It would be inter

Re: Struct delegate access corruption

2021-02-18 Thread tsbockman via Digitalmars-d-learn
On Thursday, 18 February 2021 at 08:29:48 UTC, kinke wrote: Nope, Paul is right, the copy ctors don't solve anything in this regard. Simplest example I could come up with: https://run.dlang.io/is/TgxyU3 I found that example very confusing, as it does not contain an explicit copy constructor,

Re: Strings and Slices

2021-02-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 February 2021 at 20:47:33 UTC, Mike Brown wrote: Is slices comparable to a string_view? My c++ is rusty af but yes I think so. A d slice is `struct slice { size_t length; T* ptr; }` so when in doubt just think back to what that does. string lex_identifier(ref string input)

Strings and Slices

2021-02-18 Thread Mike Brown via Digitalmars-d-learn
Hi All, I'm rebuilding a C++, and the beginning section is a lexer that uses strings, and string_view. Is slices comparable to a string_view? The architecture of the lexer is a single layer (Non-)FSM Lexer. Basically a main loop, checking the first letter of the current input position, whic

Re: How to get output of piped process?

2021-02-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/18/21 4:40 AM, frame wrote: On Thursday, 18 February 2021 at 06:04:13 UTC, Jedi wrote: Unfortunately, std.process wraps all the pipes in File structs, so you have almost no good mechanisms to properly read the data. WTF? It's just the way it is. Everything in Phobos is a C FILE * (wra

Re: null and initialized string comparisons

2021-02-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/17/21 4:16 PM, Adam D. Ruppe wrote: On Wednesday, 17 February 2021 at 20:48:22 UTC, Martin wrote: is this how it supposed to be? (https://run.dlang.io/is/7B4irm) == compares contents. Both null and "" have empty contents and are interchangable for operators that work on contents. The a

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread vitamin via Digitalmars-d-learn
On Thursday, 18 February 2021 at 15:11:44 UTC, Paul Backus wrote: On Thursday, 18 February 2021 at 14:51:09 UTC, vitamin wrote: On Thursday, 18 February 2021 at 14:43:43 UTC, Paul Backus wrote: I don't see what this buys you compared to sticking with one or the other, but you are correct that

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 18 February 2021 at 14:51:09 UTC, vitamin wrote: On Thursday, 18 February 2021 at 14:43:43 UTC, Paul Backus wrote: I don't see what this buys you compared to sticking with one or the other, but you are correct that it is technically possible. It infer function atributes (pure,

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread Mina via Digitalmars-d-learn
On Thursday, 18 February 2021 at 13:53:19 UTC, Paul Backus wrote: Another possibility is to use discriminated unions and tag-based dispatch (i.e., switch statements) instead of classes and virtual method dispatch. This would make it a bit harder to follow the book, but might be a better learnin

Re: Struct delegate access corruption

2021-02-18 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 18 February 2021 at 11:00:50 UTC, vitamin wrote: opPostMove https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1014.md can solve this problem but it isn't implemented; IIRC opPostMove has been abandoned for the same reason postblits were abandoned (issues with type-check

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread vitamin via Digitalmars-d-learn
On Thursday, 18 February 2021 at 14:43:43 UTC, Paul Backus wrote: On Thursday, 18 February 2021 at 14:26:37 UTC, vitamin wrote: Or combination of discriminate uninons and classes: /+dub.sdl: dependency "sumtype" version="~>0.10.0" +/ import std.stdio; import sumtype; alias Expression = SumTy

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 18 February 2021 at 14:26:37 UTC, vitamin wrote: Or combination of discriminate uninons and classes: /+dub.sdl: dependency "sumtype" version="~>0.10.0" +/ import std.stdio; import sumtype; alias Expression = SumType!( ExprValue, ExprBinary, ExprUnary ); class Expr{

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread vitamin via Digitalmars-d-learn
On Thursday, 18 February 2021 at 13:53:19 UTC, Paul Backus wrote: On Thursday, 18 February 2021 at 11:14:05 UTC, Mina wrote: I'm following along with the crafting interpreters book (https://craftinginterpreters.com) and it goes into implementing a visitor pattern that returns generic types, so

Re: Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 18 February 2021 at 11:14:05 UTC, Mina wrote: I'm following along with the crafting interpreters book (https://craftinginterpreters.com) and it goes into implementing a visitor pattern that returns generic types, so implementing it in D came down to the accept method causing undef

Is there an easy way to mimic generics with an accept method of a visitor pattern?

2021-02-18 Thread Mina via Digitalmars-d-learn
I'm following along with the crafting interpreters book (https://craftinginterpreters.com) and it goes into implementing a visitor pattern that returns generic types, so implementing it in D came down to the accept method causing undefined symbol error that goes away when changing it to returni

Re: Struct delegate access corruption

2021-02-18 Thread vitamin via Digitalmars-d-learn
On Thursday, 18 February 2021 at 08:29:48 UTC, kinke wrote: On Wednesday, 17 February 2021 at 20:44:46 UTC, tsbockman wrote: On Wednesday, 17 February 2021 at 20:18:53 UTC, Paul Backus wrote: [...] That bug is about postblits, this(this), not copy constructors: this(ref typeof(this)). Copy c

Re: How to get output of piped process?

2021-02-18 Thread frame via Digitalmars-d-learn
On Thursday, 18 February 2021 at 06:04:13 UTC, Jedi wrote: Unfortunately, std.process wraps all the pipes in File structs, so you have almost no good mechanisms to properly read the data. WTF? -Steve I'm wonder about this message. You can always use readln() and eof() on such kind of st

Re: Struct delegate access corruption

2021-02-18 Thread kinke via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 20:44:46 UTC, tsbockman wrote: On Wednesday, 17 February 2021 at 20:18:53 UTC, Paul Backus wrote: On Wednesday, 17 February 2021 at 19:42:00 UTC, tsbockman wrote: A copy constructor and opAssign can be used to update pointers that are relative to &this: ht