summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-05-01 20:37:14 -0700
committerKaz Kylheku <kaz@kylheku.com>2025-05-01 20:37:14 -0700
commit926875f3d3dc79001ecfd84290da8e498d45df05 (patch)
treefc2198c4cb6ec601b4a7947b73f237ca7607f320
parent5c0e21892703253846a83d3aed8e61050445c4ab (diff)
downloadtxr-926875f3d3dc79001ecfd84290da8e498d45df05.tar.gz
txr-926875f3d3dc79001ecfd84290da8e498d45df05.tar.bz2
txr-926875f3d3dc79001ecfd84290da8e498d45df05.zip
infix: phony infix requires 3 or more elements.
It is undesirable to translate (1 fun) into (fun 1). Only cases similar to these patterns, using list as an example: (1 list 2) -> (list 1 2) (1 list 2 3) -> (list 1 2 3) (1 list 2 + 3) -> (list 1 (+ 2 3)) (list 2 3) -> (list 2 3) (list 2 + 3) -> (list (+ 2 3)) * stdlib/infix.tl (infix-expand-hook): Restrict the phony infix case to three or more elements. * txr.1: Update phony infix case 1 as requiring three or more elements. Also add (1 list) example emphasizing that it's not recognized.
-rw-r--r--stdlib/infix.tl1
-rw-r--r--txr.18
2 files changed, 8 insertions, 1 deletions
diff --git a/stdlib/infix.tl b/stdlib/infix.tl
index 54d24ca9..7eee5ad7 100644
--- a/stdlib/infix.tl
+++ b/stdlib/infix.tl
@@ -305,6 +305,7 @@
(boundp tok)))
tok)
(@(require (@x @y . @rest)
+ (consp rest)
(and (not (funp env x)) (funp env y)))
(let ((rexp (infix-expand-hook rest env nil)))
(if (eq rexp rest)
diff --git a/txr.1 b/txr.1
index 6c44b77d..d81a0b3b 100644
--- a/txr.1
+++ b/txr.1
@@ -54420,7 +54420,7 @@ A form not falling into any of the above rules is recognized as "phony infix"
if it conforms to one of two situations:
.RS
.IP 1.
-It consists of at least two elements, where the first element is not
+It consists of at least three elements, where the first element is not
a function, and the second element is a function. Both the lexical and
global function namespaces are considered.
When a form is thus recognized, it is transformed by exchanging the first and
@@ -54480,6 +54480,12 @@ same manner as for the expression
which is transformed to
.codn "(list 1 (+ 2 2))" .
+The expression
+.code "(1 list)"
+is not recognized as phony infix and not thus not transformed into
+.code "(list 1)"
+because it doesn't have three or more elements.
+
Only compound expressions are recognized as infix. A sequence
of atoms like
.code "a * b"