Skip to content

Commit

Permalink
add optional fileWriter parameters to ChapelIO.write*
Browse files Browse the repository at this point in the history
Added overloads or optional parameters to each of the ChapelIO.write* procs
to allow them to be called with a fileWriter other than stdout. This allows
user code to call e.g. writeln(IO.stderr, ...) to write to stderr without
exception handling code.

Signed-off-by: Josh Milthorpe <josh.milthorpe@gmail.com>
  • Loading branch information
milthorpe committed Jun 23, 2024
1 parent 916ca4c commit c02d14a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions modules/standard/ChapelIO.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,24 @@ module ChapelIO {
proc write(const args ...?n) {
try! stdout.write((...args));
}
/* Equivalent to ``try! writer.write``. See :proc:`IO.fileWriter.write` */
proc write(writer: fileWriter, const args ...?n) {
try! writer.write((...args));
}

/* Equivalent to ``try! stdout.writeln``. See :proc:`IO.fileWriter.writeln` */
proc writeln(const args ...?n) {
try! stdout.writeln((...args));
}
/* Equivalent to ``try! writer.writeln``. See :proc:`IO.fileWriter.writeln` */
proc writeln(writer: fileWriter, const args ...?n) {
try! writer.writeln((...args));
}

// documented in the arguments version.
@chpldoc.nodoc
proc writeln() {
try! stdout.writeln();
proc writeln(writer: fileWriter = stdout) {
try! writer.writeln();
}

/* Equivalent to ``try! stdout.writef``. See
Expand All @@ -797,13 +806,27 @@ module ChapelIO {
{
try! { stdout.writef(fmt, (...args)); }
}
/* Equivalent to ``try! writer.writef``. See
:proc:`FormattedIO.fileWriter.writef`. */
proc writef(writer: fileWriter, fmt:?t, const args ...?k)
where isStringType(t) || isBytesType(t)
{
try! { writer.writef(fmt, (...args)); }
}
// documented in string version
@chpldoc.nodoc
proc writef(fmt:?t)
where isStringType(t) || isBytesType(t)
{
try! { stdout.writef(fmt); }
}
// documented in string version
@chpldoc.nodoc
proc writef(writer: fileWriter, fmt:?t)
where isStringType(t) || isBytesType(t)
{
try! { writer.writef(fmt); }
}

@chpldoc.nodoc
proc chpl_stringify_wrapper(const args ...):string {
Expand Down

0 comments on commit c02d14a

Please sign in to comment.