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");
saruftw
  • 1,104
  • 2
  • 14
  • 37
  • I thought that this was a reasonable feature request, so filed a GitHub issue against Chapel for it: https://chapel-lang.org/docs/latest/modules/standard/IO/FormattedIO.html#about-io-formatted-io – Brad Jan 03 '18 at 22:22

2 Answers2

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.

ben-albrecht
  • 1,785
  • 10
  • 23
  • 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. >>>** https://stackoverflow.com/revisions/47243896/2 – user3666197 Nov 12 '17 at 00:20
  • 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. – ben-albrecht Nov 12 '17 at 00:30
  • 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. >>> https://stackoverflow.com/posts/47243896/revisions ) – user3666197 Nov 12 '17 at 02:50
  • 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! – ben-albrecht Nov 12 '17 at 19:32
-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
         );
user3666197
  • 1
  • 6
  • 50
  • 92