From b4f23d86dd71504405f2f26278941dd8325c14ab Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 24 May 2023 06:48:18 -0700 Subject: awk: widen scope of redirection macros. This change makes it possible to use the redirection macros like -> and ->> everywhere in the awk macro, including the init-forms of the :let clause. * stdlib/awk.tl (sys:awk-mac-let-outer): New macro. (sys:awk-mac-let): Move redirection macros into awk-mac-let-outer. (awk): Rearrange the order of wrapping. We split the let so the awk-retval and aws-sym are bound outermost. Then we have the outer macros that provide the redirection operators. Then the application-defined lets inside of that. * txr.1: Documented wide scope of redirection macros. --- stdlib/awk.tl | 83 +++++++++++++++++++++++++++++++---------------------------- txr.1 | 8 ++++++ 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/stdlib/awk.tl b/stdlib/awk.tl index 1ce292ef..09065bf7 100644 --- a/stdlib/awk.tl +++ b/stdlib/awk.tl @@ -462,18 +462,21 @@ ^(symacrolet ((f (usr:rslot ,',aws-sym 'fields 'f-to-rec))) (set f (mapcar (opip ,*opip-args) f)))) (fconv (. conv-args) - ^(set f (sys:conv (,*conv-args) f))) - (-> (path . body) + ^(set f (sys:conv (,*conv-args) f)))) + ,*body))) + +(defmacro sys:awk-mac-let-outer (aws-sym . body) + ^(macrolet ((-> (path . body) ^(sys:awk-redir ,',aws-sym *stdout* :outf "w" ,path ,body)) - (->> (path . body) - ^(sys:awk-redir ,',aws-sym *stdout* :apf "a" ,path ,body)) - (<- (path . body) + (->> (path . body) + ^(sys:awk-redir ,',aws-sym *stdout* :apf "a" ,path ,body)) + (<- (path . body) ^(sys:awk-redir ,',aws-sym *stdin* :inf "r" ,path ,body)) - (!> (path . body) + (!> (path . body) ^(sys:awk-redir ,',aws-sym *stdout* :outp "w" ,path ,body)) - ( macro indicates that the file named -- cgit v1.2.3