diff options
-rw-r--r-- | share/txr/stdlib/awk.tl | 4 | ||||
-rw-r--r-- | txr.1 | 32 |
2 files changed, 35 insertions, 1 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index 7c4033e6..aab6a4eb 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -50,7 +50,9 @@ (if (plusp self.rng-n) (set self.rng-vec (vector self.rng-n))) (unless (streamp self.output) - (set self.output (open-file self.output "w"))))) + (let ((stream (open-file self.output "w"))) + (set [self.streams ^(:outf ,self.output)] stream + self.output stream))))) (defstruct sys:awk-compile-time () inputs output name lets @@ -44734,6 +44734,38 @@ can rebind causing the definition provided by .code :output to be shadowed. + +In the case when the +.code :output +argument is a string such that a new stream is opened +on the file, the +.code awk +macro will close that stream when it finishes executing. +Moreover, that stream is treated uniformly as a member of +the set of streams that are implicitly managed by the +redirection macros in the same +.code awk +macro invocation. In brief, the implication is that if +.code :output +creates a stream for the file path name +.str "out.txt" +and somewhere in the same +.code awk +macro, there is a redirection of the form, or equivalent to +.cblk +(-> "out.txt") +.cble +then this redirection shall refer to the same stream +that was established by +.codn :output . +Note also that in this example situation, the expression +.cblk +(-> "out.txt" :close) +.cble +has the effect of closing the +.code :output +stream. + .meIP (:begin << form *) All .code :begin |