summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-02-24 00:25:23 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-02-24 00:25:23 -0800
commit34530bc12e2e455b569d183937af9f41db9adbed (patch)
tree06f401350b81df769ffcdee39d30dae205c1a676
parent5a8c20fee69d0b68ee60d33a22f0fa46f724e1e2 (diff)
downloadtxr-34530bc12e2e455b569d183937af9f41db9adbed.tar.gz
txr-34530bc12e2e455b569d183937af9f41db9adbed.tar.bz2
txr-34530bc12e2e455b569d183937af9f41db9adbed.zip
opip: pass through forms in the op family.
* stdlib/op.tl (sys:opip-expand): Add op, do, lop, ldo, ap, ip, ado, ido, ret and aret to the operators whose forms are passed through untransformed. This is important because it lets us override the implicit (op ...) and (do ...) chosen by the expander. When a pipeline element produces a list, for instance, we want to be able to use (ap ...) in the next element to spread the list into arguments. * tests/012/op.tl: Add bellied numbers test case. * txr.1: Documented.
-rw-r--r--stdlib/op.tl2
-rw-r--r--tests/012/op.tl6
-rw-r--r--txr.125
3 files changed, 28 insertions, 5 deletions
diff --git a/stdlib/op.tl b/stdlib/op.tl
index 2754ca0d..1f242745 100644
--- a/stdlib/op.tl
+++ b/stdlib/op.tl
@@ -221,7 +221,7 @@
(if (atom c)
c
(let ((sym (car c)))
- (if (member sym '(dwim uref qref))
+ (if (member sym '(dwim uref qref op do lop ldo ap ip ado ido ret aret))
c
(let ((opdo (if (or (special-operator-p (car c))
(macro-form-p c e)) 'do 'op)))
diff --git a/tests/012/op.tl b/tests/012/op.tl
index 5a789219..aafe0a28 100644
--- a/tests/012/op.tl
+++ b/tests/012/op.tl
@@ -93,3 +93,9 @@
[[[[(do do do op list) 1] 2] 3] 4] (1 2 3 4)
[[[[(do do do op list @1 @@1 @@@1 @@@@1) 1] 2] 3] 4] (4 3 2 1)
[[[[(do do do op list @@@@1 @@@1 @@1 @1) 1] 2] 3] 4] (1 2 3 4))
+
+(test (flow (range 1000 9999)
+ (keep-if (opip digits (ap > (+ @2 @3) (+ @1 @4))))
+ (partition-if (op neq 1 (- @2 @1)))
+ (find-max-key @1 : len))
+ 80)
diff --git a/txr.1 b/txr.1
index 03386c86..b1cf7148 100644
--- a/txr.1
+++ b/txr.1
@@ -56777,16 +56777,31 @@ where the above
notation denotes the following transformation applied to each argument:
.verb
- (function ...) -> (op function ...)
- (operator ...) -> (do operator ...)
- (macro ...) -> (do macro ...)
+ ;; these specific form patterns are left untransformed:
+
(dwim ...) -> (dwim ...)
[...] -> [...]
(qref ...) -> (qref ...)
(uref ...) -> (uref ...)
+ (op ...) -> (op ...)
+ (do ...) -> (do ...)
+ (lop ...) -> (lop ...)
+ (ldo ...) -> (ldo ...)
+ (ap ...) -> (ap ...)
+ (ip ...) -> (ip ...)
+ (ado ...) -> (ado ...)
+ (ido ...) -> (ido ...)
+ (ret ...) -> (ret ...)
+ (aret ...) -> (aret ...)
.slot -> .slot
.(method ...) -> .(method ...)
atom -> atom
+
+ ;; other compound forms are transformed like this:
+
+ (function ...) -> (op function ...)
+ (operator ...) -> (do operator ...)
+ (macro ...) -> (do macro ...)
.brev
In other words, compound forms whose leftmost symbol is a macro or operator
@@ -56802,7 +56817,9 @@ denoting struct slot access, either explicitly using
.code uref
or
.code qref
-or the respective dot notations, as well as any atom forms.
+or the respective dot notations, forms which invoke any of the
+.code do
+family of operators, as well as any atom forms.
Note: the
.code opip