From ee37e03ec9f91e0938c4bc4eb6d03156f75c7405 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 6 Apr 2025 22:25:14 -0700 Subject: 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. --- tests/012/infix.tl | 10 ++++++++++ txr.1 | 14 ++++++++++++++ 2 files changed, 24 insertions(+) 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 -- cgit v1.2.3