From e8a06969698fe98a471ce413a81b41d4f2327bfd Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 12 Sep 2016 06:31:50 -0700 Subject: awk macro: more Awk-like treatment of prn args. * share/txr/stdlib/awk.tl (sys:awk-state prn): Use loop instead of simple interpolation, so that we we can individually interpolate each arg into a quasistring. This way if an arg is nil, it turns into nothing rather than the word "nil". * txr.1: Documented this behavior of prn. --- share/txr/stdlib/awk.tl | 7 ++++++- txr.1 | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index bb1dec1e..77d47703 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -99,7 +99,12 @@ [end-file-func aws]))))) (defmeth sys:awk-state prn (self . args) - (put-string `@{(if args args self.rec) self.ofs}@{self.ors}`)) + (cond + (args (for ((a args) next) (a) ((set a next)) + (put-string `@(car a)`) + (put-string (if (set next (cdr a)) self.ofs self.ors)))) + (t (put-string self.rec) + (put-string self.ors)))) (defun sys:awk-expander (clauses) (let ((awc (new sys:awk-compile-time))) diff --git a/txr.1 b/txr.1 index 2d8e181d..02f62750 100644 --- a/txr.1 +++ b/txr.1 @@ -37778,6 +37778,20 @@ then a call to .code prn with no arguments is the default action. +Each argument +.meta form +is printed by conversion to a string, as if by the expression +.code `@val` +where +.code val +is some variable which holds the value produced by the +evaluation of +.metn form . +Thus if the value is +.codn nil , +the output for that argument is an empty string, rather than the text +.strn nil . + .coNP Macro @ next .synb .mets (next) -- cgit v1.2.3