summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-09-24 07:23:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-09-24 07:23:58 -0700
commit97870898a2491242223a64715871cec339c42517 (patch)
tree78cb5f58277872819d67fa82d48ef10967ec8413
parentc99a38dde59aa8b0c2496fef092a93e324ec3e33 (diff)
downloadtxr-97870898a2491242223a64715871cec339c42517.tar.gz
txr-97870898a2491242223a64715871cec339c42517.tar.bz2
txr-97870898a2491242223a64715871cec339c42517.zip
awk macro: use range test logic for clause conditions.
* share/txr/stdlib/awk.tl (sys:range-test): Function renamed to sys:awk-test, since it's not just for ranges. (sys:awk-let): Uses of sys:range-test follow rename. sys:awk-test introduced into expansion of cond parts of cond-action clauses. * txr.1: Documented new behavior (conditions can produce a function or regex, which is implicitly invoked on rec).
-rw-r--r--share/txr/stdlib/awk.tl9
-rw-r--r--txr.112
2 files changed, 16 insertions, 5 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl
index eccef632..466ab544 100644
--- a/share/txr/stdlib/awk.tl
+++ b/share/txr/stdlib/awk.tl
@@ -110,7 +110,7 @@
(t (put-string self.rec)
(put-string self.ors))))
-(defun sys:range-test (val rec)
+(defun sys:awk-test (val rec)
(caseq (typeof val)
((regex fun) (call val rec))
(t val)))
@@ -200,8 +200,8 @@
(qref ,awc rng-exprs))
rng-temp))
(rng (from-expr to-expr)
- ^(sys:rng (sys:range-test ,from-expr ,(qref ,awc rng-rec-temp))
- (sys:range-test ,to-expr ,(qref ,awc rng-rec-temp))))
+ ^(sys:rng (sys:awk-test ,from-expr ,(qref ,awc rng-rec-temp))
+ (sys:awk-test ,to-expr ,(qref ,awc rng-rec-temp))))
(ff (. opip-args)
^(symacrolet ((f (rslot ,',aws-sym 'fields 'f-to-rec)))
(set f [(opip ,*opip-args) f])))
@@ -215,7 +215,8 @@
(defmacro awk (:env e . clauses)
(let ((awc (sys:awk-expander clauses)))
(with-gensyms (aws-sym awk-begf-fun awk-fun awk-endf-fun awk-retval)
- (let* ((p-actions-xform-unex (mapcar (aret ^(when ,@1 ,*@rest))
+ (let* ((p-actions-xform-unex (mapcar (aret ^(when (sys:awk-test ,@1 rec)
+ ,*@rest))
awc.cond-actions))
(p-actions-xform (sys:expand
^(sys:awk-let ,awc ,aws-sym
diff --git a/txr.1 b/txr.1
index d57dd04f..b77f6b52 100644
--- a/txr.1
+++ b/txr.1
@@ -38320,7 +38320,17 @@ variable, and various
variables are updated. Then, the condition-action clauses are processed, in the order
in which they appear. Each
.meta condition
-is evaluated. If it yields true, then its associated
+is evaluated. If the resulting value is a regular expression
+or a function, then this regular expression or function is invoked on the value
+stored in the record variable
+.codn rec ,
+and the result is taken to be the truth value of
+.metn condition .
+Otherwise, if the resulting value of
+.meta condition
+is other than a function or regular expression, it is taken directly
+to be the truth value.
+If the condition is true, then its associated
.meta action
forms are evaluated. Either way, processing passes to the next condition
clause (unless an explicit step is taken in one of the