From 263934fc9744e7bc7129d244ff6340de90468052 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 24 Feb 2022 00:25:23 -0800 Subject: 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. --- stdlib/op.tl | 2 +- tests/012/op.tl | 6 ++++++ txr.1 | 25 +++++++++++++++++++++---- 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 -- cgit v1.2.3