Is there any writef() format specifier for a bool?

Viewed 349

I looked at the writef() documentation for any bool specifier and there didn't seem to be any.

In a Chapel program I have: ...

config const verify = false;
/* that works but I want to use writef() to also print a bunch of other stuff*/
writeln("verify = " + verify); 
writef("verify = %<what-specifier-goes-here>\n", verify);

This last statement works ok.

// I guess I could do:

writef( "verify = %s\n",if verify then "true" else "false");
2 Answers

Based on the FormattedIO documentation, there is not a bool specifier available in Chapel's formatted IO.

Instead, you can use the generic specifier (%t) to print bool types in formatted IO:

config const verify = false;
writef("verify = %t\n", verify);

This specifier utilizes the writeThis or readWriteThis method of the type to print the variable. The Chapel IO documentation provides more details on how these methods work.

No, there is no such <specifier> for bool in FormattedIO

As documentation explains, there is no such bool-value specific specifier in the recent Chapel language release.

A verify value-based conversion is fine.

config const verify    =  false;
var aTrueFalseAsSTRING = "false";

if verify then aTrueFalseAsSTRING = "true";

writef( "verify = %s\n",
         aTrueFalseAsSTRING
         );
Related