From 926875f3d3dc79001ecfd84290da8e498d45df05 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 1 May 2025 20:37:14 -0700 Subject: 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. --- stdlib/infix.tl | 1 + txr.1 | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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" -- cgit v1.2.3