diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-11-27 07:13:14 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-11-27 07:13:14 -0800 |
commit | 1978069ef24ae0fdfd8bbc6c694504962759caa9 (patch) | |
tree | b98e63ae7f5daba61d684091cea1398431402b01 | |
parent | 881c54cb71ef28948a81b2890769828c2dc58cfd (diff) | |
download | txr-1978069ef24ae0fdfd8bbc6c694504962759caa9.tar.gz txr-1978069ef24ae0fdfd8bbc6c694504962759caa9.tar.bz2 txr-1978069ef24ae0fdfd8bbc6c694504962759caa9.zip |
* eval.c (eval_init): Register less and greater to
the lessv and greaterv functions instead of less and greater.
* lib.c (lessv, greaterv): New functions.
* lib.h (lessv, greaterv): Declared.
* txr.1: Document variadic nature of less and greater.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | eval.c | 4 | ||||
-rw-r--r-- | lib.c | 28 | ||||
-rw-r--r-- | lib.h | 2 | ||||
-rw-r--r-- | txr.1 | 31 |
5 files changed, 70 insertions, 6 deletions
@@ -1,3 +1,14 @@ +2014-11-27 Kaz Kylheku <kaz@kylheku.com> + + * eval.c (eval_init): Register less and greater to + the lessv and greaterv functions instead of less and greater. + + * lib.c (lessv, greaterv): New functions. + + * lib.h (lessv, greaterv): Declared. + + * txr.1: Document variadic nature of less and greater. + 2014-11-21 Kaz Kylheku <kaz@kylheku.com> * eval.c (eval_init): Register sort-group. @@ -3872,8 +3872,8 @@ void eval_init(void) reg_fun(intern(lit("flo-int"), user_package), func_n1(flo_int)); reg_fun(intern(lit("tofloat"), user_package), func_n1(tofloat)); reg_fun(intern(lit("toint"), user_package), func_n2o(toint, 1)); - reg_fun(intern(lit("less"), user_package), func_n2(less)); - reg_fun(intern(lit("greater"), user_package), func_n2(greater)); + reg_fun(intern(lit("less"), user_package), func_n1v(lessv)); + reg_fun(intern(lit("greater"), user_package), func_n1v(greaterv)); reg_fun(intern(lit("chrp"), user_package), func_n1(chrp)); reg_fun(intern(lit("chr-isalnum"), user_package), func_n1(chr_isalnum)); reg_fun(intern(lit("chr-isalpha"), user_package), func_n1(chr_isalpha)); @@ -3209,6 +3209,34 @@ val greater(val left, val right) return less(right, left); } +val lessv(val first, val rest) +{ + val iter; + + for (iter = rest; iter; iter = cdr(iter)) { + val elem = car(iter); + if (!less(first, elem)) + return nil; + first = elem; + } + + return t; +} + +val greaterv(val first, val rest) +{ + val iter; + + for (iter = rest; iter; iter = cdr(iter)) { + val elem = car(iter); + if (!less(elem, first)) + return nil; + first = elem; + } + + return t; +} + val chrp(val chr) { return (is_chr(chr)) ? t : nil; @@ -638,6 +638,8 @@ val int_flo(val f); val flo_int(val i); val less(val left, val right); val greater(val left, val right); +val lessv(val first, val rest); +val greaterv(val first, val rest); val chrp(val chr); wchar_t c_chr(val chr); val chr_isalnum(val ch); @@ -17466,18 +17466,38 @@ The sequence or hash table is returned. .coNP Function @ less .synb -.mets (less < left-obj << right-obj ) +.mets (less < left-obj << right-obj ) +.mets (less < obj << obj *) .syne .desc The .code less -function determines whether +function, when called with two arguments, determines whether .meta left-obj compares less than .meta right-obj in a generic way which handles arguments of various types. -The function is used as the default for the +The argument syntax of +.code less +is generalized. It can accept one argument, in which case it unconditionally +returns +.code t +regardless of that argument's value. If more than two arguments are +given, then +.code less +generalizes in a way which can be described by the following equivalence +pattern, with the understanding that each argument expression +is evaluated exactly once: + +.cblk + (less a b c) <--> (and (less a b) (less b c)) + (less a b c d) <--> (and (less a b) (less b c) (less c d)) +.cble + +The +.code less +function is used as the default for the .meta lessfun argument of the functions .code sort @@ -17600,6 +17620,7 @@ types, the situation is an error. .coNP Function @ greater .synb .mets (greater < left-obj << right-obj ) +.mets (greater < obj << obj *) .syne .desc The @@ -17608,10 +17629,12 @@ greater function is equivalent to .code less with the arguments reversed. That is to say, the following -equivalence holds: +equivalences hold: .cblk + (greater a <--> (less a) <--> t (greater a b) <--> (less b a) + (greater a b c ...) <--> (less ... c b a) .cble The |