Skip to content

Improvements for ASR Print node #2543

@Thirumalai-Shaktivel

Description

@Thirumalai-Shaktivel

We could do it like this:

--- a/src/libasr/ASR.asdl
+++ b/src/libasr/ASR.asdl
@@ -193,7 +193,7 @@ stmt
     | GoToTarget(int id, identifier name)
     | If(expr test, stmt* body, stmt* orelse)
     | IfArithmetic(expr test, int lt_label, int eq_label, int gt_label)
-    | Print(expr? fmt, expr* values, expr? separator, expr? end)
+    | Print(expr text)
     | FileOpen(int label, expr? newunit, expr? filename, expr? status, expr? form)
     | FileClose(int label, expr? unit, expr? iostat, expr? iomsg, expr? err, expr? status)
     | FileRead(int label, expr? unit, expr? fmt, expr? iomsg, expr? iostat, expr? id, expr* values)

That makes sense to me.

Then the next question is how to support the very common case of print *, a, b, c (Fortran) and print(a, b, c) (Python), where the print formatting is automatically set based on the types. One could do that using:

-    | StringFormat(expr fmt, expr* args, string_format_kind kind, ttype type, expr? value)
+    | StringFormat(expr? fmt, expr* args, string_format_kind kind, ttype type, expr? value)

Where if the "fmt" is not present, the arguments will just be printed based on the kind argument. Regarding separator and end, those are rare cases, and I would just create an explicit format string in those cases, and not special case it in any way.

Originally posted by @certik in #2471 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    asrASR Related changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions