Replacement for %.8ht

I was used to using %t and %.8ht to print the domains and values of arrays I didn't necessarily know the dimensions in debug builds and testing but I can't find an alternative now that these specifiers have been discontinued. Is there an easier way than just using loops?

For the moment I've just replaced

writef("Left side %ht: %.8ht\n", consL.domain, consL);


writef("Left side %?: %?\n", consL.domain, consL);

But there are two issues. One is using the Chapel format and the other is specifying the number of decimal digits.

For 1 the solution seems to be specifying the chplSerializer when creating a writer, but it seems like stdout is already a writer, not a file so this won't work.

stdout.writer(serializer = new chplSerializer()).writef("Left side %?: %?\n", consL.domain, consL)

and I couldn't find any reference to a stdout file in the documentation.

For 2 it seems like there is no way to give a format specifier like %+20.12er for a serializer to apply to all real numbers.

I'm kinda bummed because serializers seemed like a great way to support more formats other than JSON and replace the TOML module but this is a lot of convenience lost.

1 Like

Hi @RedHatTurtle

Thanks very much for the time to send us your feedback, which is valuable as we try to wrap up the Chapel 2.0 release. Most of the team is currently on winter break, and I'm not sure whether anyone who has worked on this issue is still around and online or not, so wanted to let you know if you don't hear from us before the new year, it's due to vacation schedules and not the content of your message itself. (I'm personally not expert on this topic, so don't want to reply until others have had a chance to weigh in).

Thanks again for taking the time to let us know about your use cases and challenges, and I hope you have some vacation time coming up as well,

1 Like

Hi @RedHatTurtle,

Thanks for the feedback!

WRT your first question, you can use the fileWriter.withSerializer method, which effectively clones a fileWriter, but uses a serializer of the provided type. See the docs here. In this case, that would look like:

stdout.withSerializer(new chplSerializer()).writef(...);

where you'd get:

Left side ["1..3"]: [1, 2, 3]

(The docs for stdout can be found here)

For your second question, unfortunately the %? formatter doesn't accept a precision argument (although this is something we've discussed supporting). In the meantime, you could use a loop to write each element individually as you mentioned, or I could provide a clone of the chplSerializer that has a global precision option — let me know if that's something that would be helpful.



Thank you @jcorrado!

Using the chapel serializer was even better than I expected since it forced exponential notation and a consistent 6-digit precision besides the square braces outside arrays. This is good enough for me for the moment.

One difference that I found is that domains were enclosed in square braces and quotes instead of curly braces. Not sure if it was an intentional change but I really like the old notation for domains.

New style

Left  2 ["1..4"]: [1.225000e+00, 2.491643e+02, 2.179905e+01, 2.788464e+05]

Old style:

 Left  2 {1..4}: [1.22500000e+00, 2.49164316e+02, 2.17990530e+01, 2.78846400e+05]

Out of curiosity, I also tested it for multidimensional domains/arrays, which makes it look like the quotes might come from the range format and not the domain, i.e. ["1..3", "1..5"]. I hope support for multidimensional arrays is on the plans but it's not something I use nearly as much.

Lastly, I've skimmed the discussion you linked and I like your proposal. If I'm ever at the point of using different precisions in the same writer I don't think I would mind writing precisely defined formats instead of relying on automatic/generic formatting.

Anyway, thank you again for the help (especially at this time of the year), and happy holidays to you, Brad, and the rest of the team!

1 Like

Sure thing!

The change to domain formatting is a part of our ongoing effort to stabilize the (de)serializers interface. Currently domains get printed as a "list" of ranges when using the non-default format (thus the square-brackets), but we would like to support more specific formatting rules that would allow the chplFormat to print them in the older style.

See this issue for more information: chplSerializer does not output domains as expected · Issue #24123 · chapel-lang/chapel · GitHub and feel free to include any thoughts or feedback there as well.



Hi @RedHatTurtle

Just in case you didn't subscribe to the issue, @benharsh merged Fix chplSerializer formatting for domains and ranges by benharsh · Pull Request #24145 · chapel-lang/chapel · GitHub today, which should put this back into the state you preferred. If you have a chance to check it out and verify that's the case, that'd be great!


1 Like

Thank you for the reminder @bradcray

I was indeed following the issue but only got to test the PR today and it worked like a charm.
Thank you @benharsh and @jcorrado for the help and fix!

@RedHatTurtle : Great, thanks for verifying, and thanks again for reporting this to us!