summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--share/txr/stdlib/awk.tl6
-rw-r--r--txr.129
2 files changed, 32 insertions, 3 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index 466ab544..eb07cdcc 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -35,7 +35,8 @@
(file-num 0)
(file-rec-num 0)
(rec-num 0)
- rec fields nf rng-vec (rng-n 0)
+ rec orig-rec fields nf
+ rng-vec (rng-n 0)
(:postinit (self)
(if (plusp self.rng-n)
(set self.rng-vec (vector self.rng-n)))
@@ -93,7 +94,7 @@
aws.krs))))
(set aws.file-rec-num 0)
(whilet ((rec (get-line recin)))
- (set aws.rec rec)
+ (set aws.rec rec aws.orig-rec rec)
(inc aws.rec-num)
(inc aws.file-rec-num)
aws.(rec-to-f)
@@ -167,6 +168,7 @@
(defmacro sys:awk-let (awc aws-sym . body)
^(symacrolet ((rec (rslot ,aws-sym 'rec 'rec-to-f))
+ (orec (rslot ,aws-sym 'orig-rec 'rec-to-f))
(f (rslot ,aws-sym 'fields 'f-to-rec))
(nf (rslot ,aws-sym 'nf 'nf-to-f))
(nr (qref ,aws-sym rec-num))
diff --git a/txr.1 b/txr.1
index 11f23cec..fef7e0a4 100644
--- a/txr.1
+++ b/txr.1
@@ -38346,7 +38346,7 @@ switches to the next input source. When there are no more input sources,
the macro terminates.
.RE
-.coNP Variable @ rec
+.coNP Variables @ rec and @ orec
.desc
The awk variable
.code rec
@@ -38368,6 +38368,33 @@ and these fields are assigned to the field list
At the same time, the
.code nf
variable is updated to reflect the new number of fields.
+Likewise, modification of these variables causes
+.code rec
+to be reconstructed by a catenation of the textual representation
+of the fields in
+.code f
+separated by copies of the output field separator
+.codn ofs .
+
+The
+.code orec
+variable ("original record") also holds the current record. It is automatically
+updated prior to the processing of the condition-clauses at the same time as
+.code rec
+with the same contents. Like
+.codn rec ,
+it is initially
+.code nil
+before the first record is read. The
+.code orec
+variable is unaffected by modification of
+the variables
+.codn rec ,
+.code f
+and
+.codn nf .
+It may be assigned. Doing so has no effect on any other
+variable.
.coNP Variable @ f
.desc