www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to invert bool false/true in alias compose?

reply Marcone <marcone email.com> writes:
import std;

alias cmd = compose!(to!bool, wait, spawnShell, to!string);

void main(){
	writeln(cmd("where notepad.exe"));
}


Result:

C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe
false


The result show "false" because good spawnshell command return 0 
and 0 to bool is false. But I want to invert false to true to get 
true or false if command success.
Dec 06 2019
next sibling parent reply mipri <mipri minimaltype.com> writes:
On Saturday, 7 December 2019 at 04:00:53 UTC, Marcone wrote:
 import std;

 alias cmd = compose!(to!bool, wait, spawnShell, to!string);

 void main(){
 	writeln(cmd("where notepad.exe"));
 }


 Result:

 C:\Windows\System32\notepad.exe
 C:\Windows\notepad.exe
 false


 The result show "false" because good spawnshell command return 
 0 and 0 to bool is false. But I want to invert false to true to 
 get true or false if command success.
These all work: alias cmd = compose!(unaryFun!"!a", to!bool, wait, spawnShell, to!string); alias cmd = compose!("!a", to!bool, wait, spawnShell, to!string); alias cmd = compose!(b => !b, to!bool, wait, spawnShell, to!string);
Dec 06 2019
parent Marcone <marcone email.com> writes:
On Saturday, 7 December 2019 at 04:05:23 UTC, mipri wrote:
 On Saturday, 7 December 2019 at 04:00:53 UTC, Marcone wrote:
 import std;

 alias cmd = compose!(to!bool, wait, spawnShell, to!string);

 void main(){
 	writeln(cmd("where notepad.exe"));
 }


 Result:

 C:\Windows\System32\notepad.exe
 C:\Windows\notepad.exe
 false


 The result show "false" because good spawnshell command return 
 0 and 0 to bool is false. But I want to invert false to true 
 to get true or false if command success.
These all work: alias cmd = compose!(unaryFun!"!a", to!bool, wait, spawnShell, to!string); alias cmd = compose!("!a", to!bool, wait, spawnShell, to!string); alias cmd = compose!(b => !b, to!bool, wait, spawnShell, to!string);
Thank you very much mipri! Work very well!
Dec 06 2019
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 07.12.19 05:00, Marcone wrote:
 import std;
 
 alias cmd = compose!(to!bool, wait, spawnShell, to!string);
 
 void main(){
      writeln(cmd("where notepad.exe"));
 }
 
 
 Result:
 
 C:\Windows\System32\notepad.exe
 C:\Windows\notepad.exe
 false
 
 
 The result show "false" because good spawnshell command return 0 and 0 
 to bool is false. But I want to invert false to true to get true or 
 false if command success.
alias cmd = compose!(not!(to!bool), wait, spawnShell, to!string);
Dec 06 2019