From 290d470eb4c96f12b78667d286d2a11c49d2a619 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 15 Nov 2014 16:58:58 -0800 Subject: * lib.c (max2, min2): Use the less comparison function for generic semantics. * lib.h (max2, min2): Parameter names changed to avoid suggesting that the operands are numbers. * txr.1: Documentation for min and max updated. --- ChangeLog | 10 ++++++++++ lib.c | 8 ++++---- lib.h | 4 ++-- txr.1 | 11 +++++++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7443d7c6..33590a1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2014-11-15 Kaz Kylheku + + * lib.c (max2, min2): Use the less comparison function + for generic semantics. + + * lib.h (max2, min2): Parameter names changed to avoid suggesting + that the operands are numbers. + + * txr.1: Documentation for min and max updated. + 2014-11-10 Kaz Kylheku * eval.c (opip_s, oand_s, chain_s, chand_s): New global variables. diff --git a/lib.c b/lib.c index a06dfa7e..62d43b67 100644 --- a/lib.c +++ b/lib.c @@ -2139,14 +2139,14 @@ val numneqv(val list) return t; } -val max2(val anum, val bnum) +val max2(val a, val b) { - return if3(ge(anum, bnum), anum, bnum); + return if3(less(a, b), b, a); } -val min2(val anum, val bnum) +val min2(val a, val b) { - return if3(le(anum, bnum), anum, bnum); + return if3(less(a, b), a, b); } val maxv(val first, val rest) diff --git a/lib.h b/lib.h index 086967b0..fafad0cf 100644 --- a/lib.h +++ b/lib.h @@ -553,8 +553,8 @@ val gev(val first, val rest); val lev(val first, val rest); val numeqv(val first, val rest); val numneqv(val list); -val max2(val anum, val bnum); -val min2(val anum, val bnum); +val max2(val a, val b); +val min2(val a, val b); val maxv(val first, val rest); val minv(val first, val rest); val expt(val base, val exp); diff --git a/txr.1 b/txr.1 index 3b6b99f2..409fe8a3 100644 --- a/txr.1 +++ b/txr.1 @@ -18492,20 +18492,23 @@ and functions determine and return the highest or lowest value from among their arguments. -The arguments must be numbers or characters. - If only .meta first-arg is given, that value is returned. +These functions are type generic, since they compare arguments +using the same semantics as the +.code less +function. + If two or more arguments are given, then .code (max a b) is equivalent to -.codn (if (>= a b) a b) , +.codn (if (less a b) b a) , and .code (min a b) is equivalent to -.codn (if (<= a b) a b) . +.codn (if (less a b) a b) . If the operands do not have the same type, then one of them is converted to the type of the other; however, the original unconverted values are returned. For instance -- cgit v1.2.3