Re: D: How do I pipe (|) through three programs using std.process?
Latest iteration on this thread. Limitations: * pipes through two programs. * very verbose, hard to use. ``` import std; import std.process; version (Windows) { enum Find = "find"; } version (Posix) { enum Find = "grep"; } void pipeTo(Pipe p, string nextprogram){ spawnShell(nextprogram, p.readEnd, stdout); } auto program(string name){ Pipe p = std.process.pipe; spawnShell(name, stdin, p.writeEnd); return p; } void main() { program("echo HelloWorld").pipeTo(nextprogram: Find ~ ` "HelloWorld"`); } ```
Re: D: How to check if a function is chained? a().b().c();
On Saturday, 18 November 2023 at 07:47:19 UTC, BoQsc wrote: Let's say we have a chain of functions. ``` a().b().c(); ``` I would like to have a behaviour in `a()` that would check if there is `b()` or `c()` chained to it. If `a();`is not chained: do a `writeln("You forgot to chain this function!");` A function that executes a program For me syntactically it is important. One real world application would be: `program("someProgramName").pipe("someOtherProgramName");` Executes and pipes output to another program. `program();` - Only executes the program. It would be easy if you have some kind of aspect oriented framework. Other than that I guess you need to check the trace info (or possibly trait).
Re: D: How to check if a function is chained? a().b().c();
On Saturday, 18 November 2023 at 07:47:19 UTC, BoQsc wrote: Let's say we have a chain of functions. ``` a().b().c(); ``` I would like to have a behaviour in `a()` that would check if there is `b()` or `c()` chained to it. If `a();`is not chained: do a `writeln("You forgot to chain this function!");` A function that executes a program For me syntactically it is important. One real world application would be: `program("someProgramName").pipe("someOtherProgramName");` Executes and pipes output to another program. `program();` - Only executes the program. Consider adding @mustuse on the return type. https://dlang.org/spec/attribute.html#mustuse-attribute -Steve
Re: D: How to check if a function is chained? a().b().c();
On Saturday, 18 November 2023 at 07:47:19 UTC, BoQsc wrote: `program("someProgramName").pipe("someOtherProgramName");` Executes and pipes output to another program. `program();` - Only executes the program. Serious answer: have a function handle this, instead of the semicolon. `program("p1").pipe("p2").run;` - does that `program("p1").run;` - does the other Supposedly this is the "builder pattern" but the wikipedia entry seems to be deliberately bad. Unserious answer, especially unsuitable for your concrete example where you probably want subprocesses to run reliably and in order: do something with object lifetime functions. ```d import std.stdio : writeln; class Program { string program; bool used; this(string p) { program = p; } ~this() { if (!used) writeln("You forgot to chain program: ", program); } } Program a(string p) { return new Program(p); } void b(Program p) { p.used = true; writeln("using program: ", p.program); } void main() { a("2"); a("1").b(); } ```
Re: Dirty DMD
On Saturday, 18 November 2023 at 18:52:07 UTC, JN wrote: Latest DMD for Windows downloaded from here: https://downloads.dlang.org/releases/2.x/2.105.3/dmd-2.105.3.exe reports version as dirty: DMD64 D Compiler v2.105.3-dirty Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved written by Walter Bright what does it mean by dirty? Oops. It means whoever built it had uncommitted changes in their version of the code. It's probably harmless though - somebody trying to smuggle in changes could just disable that annotation.
Re: Dirty DMD
On Saturday, 18 November 2023 at 18:52:07 UTC, JN wrote: Latest DMD for Windows downloaded from here: https://downloads.dlang.org/releases/2.x/2.105.3/dmd-2.105.3.exe reports version as dirty: DMD64 D Compiler v2.105.3-dirty Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved written by Walter Bright what does it mean by dirty? Something in the build process changes a file and therefore the thing that checks the version marks it as dirty. It’s perfectly fine, this is the official release. It’s a bit embarrassing to be honest. The windows binaries have been reporting dirty for years and nobody cares to fix it. -Steve