summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-04-06 22:25:14 -0700
committerKaz Kylheku <kaz@kylheku.com>2025-04-06 22:25:14 -0700
commitee37e03ec9f91e0938c4bc4eb6d03156f75c7405 (patch)
tree7486739c06045eb82f2cb6eeaadc1a7e9ae9cb9b
parent6feec15b59de91e753e0ab55e748c2ec6192b80a (diff)
downloadtxr-ee37e03ec9f91e0938c4bc4eb6d03156f75c7405.tar.gz
txr-ee37e03ec9f91e0938c4bc4eb6d03156f75c7405.tar.bz2
txr-ee37e03ec9f91e0938c4bc4eb6d03156f75c7405.zip
infix: add quadratic-roots test
* tests/012/infix.tl (quadractic-roots): New function. Add couple of tests. * txr.1: Add quadratic-roots as example to ifx macro.
-rw-r--r--tests/012/infix.tl10
-rw-r--r--txr.114
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/012/infix.tl b/tests/012/infix.tl
index c619db18..79767f31 100644
--- a/tests/012/infix.tl
+++ b/tests/012/infix.tl
@@ -65,3 +65,13 @@
(x ** a[i][j][k] ++) (expt x (pinc [[[a i] j] k]))
(x ** -- a[i][j][k]) (expt x (dec [[[a i] j] k]))
(x ** -- a[i + y][j ++][-- k]) (expt x (dec [[[a i + y] j ++] -- k])))
+
+(ifx
+ (defun quadratic-roots (a b c)
+ (let ((d (sqrt b * b - 4 * a * c)))
+ (list ((- b + d) / 2 * a)
+ ((- b - d) / 2 * a)))))
+
+(mtest
+ (quadratic-roots 1 0 -4) (2.0 -2.0)
+ (quadratic-roots 1 2 1) (-1.0 -1.0))
diff --git a/txr.1 b/txr.1
index b2b01fb9..2e2597ab 100644
--- a/txr.1
+++ b/txr.1
@@ -54327,6 +54327,20 @@ continues to apply, infix subexpressions produced by
.code parse-infix
are recursively detected and expanded.
+.TP* Example
+
+Calculate the roots of a quadratic formula, when real:
+
+.verb
+ (ifx
+ (defun quadratic-roots (a b c)
+ (let ((d (sqrt b * b - 4 * a * c)))
+ (list ((- b + d) / 2 * a)
+ ((- b - d) / 2 * a)))))
+
+ (quadratic-roots 1 0 -4) -> (2.0 -2.0)
+ (quadratic-roots 1 2 1) -> (-1.0 -1.0)
+.brev
.SS* Enumerated Constants
The enumerated constants module provides ways for defining