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

2

7

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");
Rundell answered 11/11, 2017 at 22:21 Comment(1)
I thought that this was a reasonable feature request, so filed a GitHub issue against Chapel for it: chapel-lang.org/docs/latest/modules/standard/IO/…Brien
A
3

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.

Awesome answered 11/11, 2017 at 23:26 Comment(4)
With all due respect Ben, what was any rational reason to roll back the improvement edits -- one corrected typo and added a more accurate explanation about the Chapel actually not having any writef(...)-formatting specifier for bool-eans, but having a possibility to use a smart-trick with a delegation of the FormattedIO presentation of a bool-hard-typed value ( brought in by the verify constant ) onto its own type-inherrited writeThis() routine? Any missed reason? Ref. >>> stackoverflow.com/revisions/47243896/2Goldi
Hey - sorry, I wish you could document rollbacks the same way you can document edits. I think the extra detail was good, but did not agree with the other minor edits.Awesome
Not clear which exact part ( if any at all ) of the "minor edits" as you call it, have deserved your particular feeling that you cannot agree with their respective meaning so strong, that you have initiated a roll-back. Be rather specific and exact + argument why -- no exceptions, no excuse in this -- otherwise there still seems no rational reason for a roll-back. ( Btw -- as per your wish -- anyone can document calling a roll-back Ref. >>> stackoverflow.com/posts/47243896/revisions )Goldi
Apologies if I've broken SO etiquette by rolling back your edit. I've reincorporated the edits that I agreed with. Hopefully this is more clear. Thanks!Awesome
G
-1

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
         );
Goldi answered 11/11, 2017 at 23:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.