summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog22
-rw-r--r--eval.c1
-rw-r--r--lib.c24
-rw-r--r--lib.h5
-rw-r--r--txr.146
-rw-r--r--txr.vim218
6 files changed, 188 insertions, 128 deletions
diff --git a/ChangeLog b/ChangeLog
index 83842ce1..5502d551 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
2014-10-13 Kaz Kylheku <kaz@kylheku.com>
+ * eval.c (eval_init): Register greater function as intrinsic.
+
+ * lib.c (gt_f, lt_f): Global variables removed.
+ (greater_f): New variable.
+ (greater): New function.
+ (find_max, pos_max): Use greater_f as default for testfun,
+ rather than gt_f.
+ (find_min, pos_min): Use less_f as default for testfun,
+ rather than lt_f.
+ (obj_init): Remove references to gt_f and lt_f.
+ GC-protect and initialize greater_f.
+
+ * lib.h (greater_f): Declared.
+ (gt_f, lt_f): Declarations removed.
+
+ * txr.1: Documented greater, and use of less and greater
+ in pos-min, pos-max, find-min and find-max.
+
+ * txr.vim: Regenerated.
+
+2014-10-13 Kaz Kylheku <kaz@kylheku.com>
+
* genvim.txr (sortuniq): Remove unnecessary function,
since (sortuniq list) can be done as (sort (uniq list)).
diff --git a/eval.c b/eval.c
index f8ea3cee..753d0211 100644
--- a/eval.c
+++ b/eval.c
@@ -3785,6 +3785,7 @@ void eval_init(void)
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("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));
diff --git a/lib.c b/lib.c
index e59ad0ac..d25e47e3 100644
--- a/lib.c
+++ b/lib.c
@@ -97,8 +97,8 @@ val null_string;
val nil_string;
val null_list;
-val identity_f, equal_f, eql_f, eq_f, gt_f, lt_f, car_f, cdr_f, null_f;
-val list_f, less_f;
+val identity_f, equal_f, eql_f, eq_f, car_f, cdr_f, null_f;
+val list_f, less_f, greater_f;
val prog_string;
@@ -3147,6 +3147,11 @@ val less(val left, val right)
internal_error("unhandled case in less function");
}
+val greater(val left, val right)
+{
+ return less(right, left);
+}
+
val chrp(val chr)
{
return (is_chr(chr)) ? t : nil;
@@ -5660,7 +5665,7 @@ val find_max(val seq_in, val testfun, val keyfun)
if (!seq)
return nil;
- testfun = default_arg(testfun, gt_f);
+ testfun = default_arg(testfun, greater_f);
keyfun = default_arg(keyfun, identity_f);
maxelt = car(seq_in);
@@ -5680,7 +5685,7 @@ val find_max(val seq_in, val testfun, val keyfun)
val find_min(val seq, val testfun, val keyfun)
{
- return find_max(seq, default_arg(testfun, lt_f), keyfun);
+ return find_max(seq, default_arg(testfun, less_f), keyfun);
}
val find_if(val pred, val list, val key)
@@ -5784,7 +5789,7 @@ val pos_max(val seq_in, val testfun, val keyfun)
if (!seq)
return nil;
- testfun = default_arg(testfun, gt_f);
+ testfun = default_arg(testfun, greater_f);
keyfun = default_arg(keyfun, identity_f);
maxkey = funcall1(keyfun, car(seq));
@@ -5803,7 +5808,7 @@ val pos_max(val seq_in, val testfun, val keyfun)
val pos_min(val seq, val testfun, val keyfun)
{
- return pos_max(seq, default_arg(testfun, lt_f), keyfun);
+ return pos_max(seq, default_arg(testfun, less_f), keyfun);
}
val set_diff(val list1, val list2, val testfun, val keyfun)
@@ -6209,9 +6214,9 @@ static void obj_init(void)
protect(&packages, &system_package_var, &keyword_package_var,
&user_package_var, &null_string, &nil_string,
- &null_list, &equal_f, &eq_f, &eql_f, &gt_f, &lt_f,
+ &null_list, &equal_f, &eq_f, &eql_f,
&car_f, &cdr_f, &null_f, &list_f,
- &identity_f, &less_f, &prog_string, &env_list,
+ &identity_f, &less_f, &greater_f, &prog_string, &env_list,
(val *) 0);
nil_string = lit("nil");
@@ -6336,14 +6341,13 @@ static void obj_init(void)
equal_f = func_n2(equal);
eq_f = func_n2(eq);
eql_f = func_n2(eql);
- gt_f = func_n2(gt);
- lt_f = func_n2(lt);
identity_f = func_n1(identity);
car_f = func_n1(car);
cdr_f = func_n1(cdr);
null_f = func_n1(null);
list_f = func_n0v(identity);
less_f = func_n2(less);
+ greater_f = func_n2(greater);
prog_string = string(progname);
}
diff --git a/lib.h b/lib.h
index bb58669c..cf1a8d4f 100644
--- a/lib.h
+++ b/lib.h
@@ -378,8 +378,8 @@ extern val nothrow_k, args_k, colon_k, auto_k;
extern val null_string;
extern val null_list; /* (nil) */
-extern val identity_f, equal_f, eql_f, eq_f, gt_f, lt_f, car_f, cdr_f, null_f;
-extern val list_f, less_f;
+extern val identity_f, equal_f, eql_f, eq_f, car_f, cdr_f, null_f;
+extern val list_f, less_f, greater_f;
extern const wchar_t *progname;
extern val prog_string;
@@ -601,6 +601,7 @@ val num_str(val str);
val int_flo(val f);
val flo_int(val i);
val less(val left, val right);
+val greater(val left, val right);
val chrp(val chr);
wchar_t c_chr(val chr);
val chr_isalnum(val ch);
diff --git a/txr.1 b/txr.1
index 6b23e402..e2d14372 100644
--- a/txr.1
+++ b/txr.1
@@ -13025,12 +13025,11 @@ argument. If
is not given, then the pos-max function defaults
.meta testfun
to the
-.code >
-("greater than") function, whereas
+.code greater
+function, whereas
.code pos-min
defaults it to the
-.code <
-("less than")
+.code less
function.
If
@@ -13438,11 +13437,11 @@ argument. If
.meta testfun
is not given, then the find-max function defaults it to
the
-.code >
+.code greater
function, whereas
.code find-min
defaults it to the
-.code <
+.code less
function.
Without a
@@ -17254,7 +17253,13 @@ The function is used as the default for the
argument of the functions
.code sort
and
-.codn merge .
+.codn merge ,
+as well as the
+.meta testfun
+argument of the
+.code pos-min
+and
+.codn find-min .
The
.code less
@@ -17363,6 +17368,33 @@ a nonempty list.
Finally, if either of the arguments has a type other than the above discussed
types, the situation is an error.
+.coNP Function @ greater
+.synb
+.mets (greater < left-obj << right-obj )
+.syne
+.desc
+The
+.code
+greater
+function is equivalent to
+.code less
+with the arguments reversed. That is to say, the following
+equivalence holds:
+
+.cblk
+ (greater a b) <--> (less b a)
+.cble
+
+The
+.code greater
+function is used as the default for the
+.meta testfun
+argument of the
+.code pos-max
+and
+.code find-max
+functions.
+
.coNP Function @ sort
.synb
.mets (sort < sequence >> [ lessfun <> [ keyfun ]])
diff --git a/txr.vim b/txr.vim
index 1622f31f..7bd4e810 100644
--- a/txr.vim
+++ b/txr.vim
@@ -83,115 +83,115 @@ syn keyword txl_keyword contained functionp gcd gen generate
syn keyword txl_keyword contained gensym get-byte get-char get-hash-userdata
syn keyword txl_keyword contained get-line get-lines get-list-from-stream get-sig-handler
syn keyword txl_keyword contained get-string get-string-from-stream gethash getitimer
-syn keyword txl_keyword contained getpid getppid giterate group-by
-syn keyword txl_keyword contained gun hash hash-alist hash-construct
-syn keyword txl_keyword contained hash-count hash-diff hash-eql hash-equal
-syn keyword txl_keyword contained hash-isec hash-keys hash-pairs hash-uni
-syn keyword txl_keyword contained hash-update hash-update-1 hash-values hashp
-syn keyword txl_keyword contained html-decode html-encode iapply identity
-syn keyword txl_keyword contained ido if iff iffi
-syn keyword txl_keyword contained inc inhash int-flo int-str
-syn keyword txl_keyword contained integerp intern interp-fun-p interpose
-syn keyword txl_keyword contained ip ipf isqrt itimer-prov
-syn keyword txl_keyword contained itimer-real itimer-virtual juxt keep-if
-syn keyword txl_keyword contained keep-if* keywordp kill labels
-syn keyword txl_keyword contained lambda last lazy-str lazy-str-force
-syn keyword txl_keyword contained lazy-str-force-upto lazy-str-get-trailing-list lazy-stream-cons lazy-stringp
-syn keyword txl_keyword contained lbind lcons-fun lconsp ldiff
-syn keyword txl_keyword contained length length-list length-str length-str-<
-syn keyword txl_keyword contained length-str-<= length-str-> length-str->= length-vec
-syn keyword txl_keyword contained less let let* link
-syn keyword txl_keyword contained lisp-parse list list* list-str
-syn keyword txl_keyword contained list-vector listp log log-alert
-syn keyword txl_keyword contained log-auth log-authpriv log-cons log-crit
-syn keyword txl_keyword contained log-daemon log-debug log-emerg log-err
-syn keyword txl_keyword contained log-info log-ndelay log-notice log-nowait
-syn keyword txl_keyword contained log-odelay log-perror log-pid log-user
-syn keyword txl_keyword contained log-warning log10 log2 logand
-syn keyword txl_keyword contained logior lognot logtest logtrunc
-syn keyword txl_keyword contained logxor macro-form-p macro-time macroexpand
-syn keyword txl_keyword contained macroexpand-1 macrolet major make-catenated-stream
-syn keyword txl_keyword contained make-env make-hash make-lazy-cons make-like
-syn keyword txl_keyword contained make-package make-random-state make-similar-hash make-string-byte-input-stream
-syn keyword txl_keyword contained make-string-input-stream make-string-output-stream make-strlist-output-stream make-sym
-syn keyword txl_keyword contained make-time make-time-utc make-trie makedev
-syn keyword txl_keyword contained mapcar mapcar* mapdo maphash
-syn keyword txl_keyword contained mappend mappend* mask match-fun
-syn keyword txl_keyword contained match-regex match-regex-right match-str match-str-tree
-syn keyword txl_keyword contained max member member-if memq
-syn keyword txl_keyword contained memql memqual merge min
-syn keyword txl_keyword contained minor mkdir mknod mkstring
-syn keyword txl_keyword contained mod multi multi-sort n-choose-k
-syn keyword txl_keyword contained n-perm-k nconc nilf none
-syn keyword txl_keyword contained not nreverse null nullify
-syn keyword txl_keyword contained num-chr num-str numberp oddp
-syn keyword txl_keyword contained op open-command open-directory open-file
-syn keyword txl_keyword contained open-files open-files* open-pipe open-process
-syn keyword txl_keyword contained open-tail openlog or orf
-syn keyword txl_keyword contained packagep partition partition* partition-by
-syn keyword txl_keyword contained perm pop pos pos-if
-syn keyword txl_keyword contained pos-max pos-min posq posql
-syn keyword txl_keyword contained posqual pprinl pprint pprof
-syn keyword txl_keyword contained prinl print prof prog1
-syn keyword txl_keyword contained progn prop proper-listp push
-syn keyword txl_keyword contained pushhash put-byte put-char put-line
-syn keyword txl_keyword contained put-lines put-string put-strings pwd
-syn keyword txl_keyword contained qquote quasi quasilist quote
-syn keyword txl_keyword contained rand random random-fixnum random-state-p
-syn keyword txl_keyword contained range range* range-regex rcomb
-syn keyword txl_keyword contained read readlink real-time-stream-p reduce-left
-syn keyword txl_keyword contained reduce-right ref refset regex-compile
-syn keyword txl_keyword contained regex-parse regexp regsub rehome-sym
-syn keyword txl_keyword contained remhash remove-if remove-if* remove-path
-syn keyword txl_keyword contained remq remq* remql remql*
-syn keyword txl_keyword contained remqual remqual* rename-path repeat
-syn keyword txl_keyword contained replace replace-list replace-str replace-vec
-syn keyword txl_keyword contained rest ret retf return
-syn keyword txl_keyword contained return-from reverse rlcp rperm
-syn keyword txl_keyword contained rplaca rplacd run s-ifblk
-syn keyword txl_keyword contained s-ifchr s-ifdir s-ififo s-iflnk
-syn keyword txl_keyword contained s-ifmt s-ifreg s-ifsock s-irgrp
-syn keyword txl_keyword contained s-iroth s-irusr s-irwxg s-irwxo
-syn keyword txl_keyword contained s-irwxu s-isgid s-isuid s-isvtx
-syn keyword txl_keyword contained s-iwgrp s-iwoth s-iwusr s-ixgrp
-syn keyword txl_keyword contained s-ixoth s-ixusr search search-regex
-syn keyword txl_keyword contained search-str search-str-tree second seek-stream
-syn keyword txl_keyword contained select seqp set set-diff
-syn keyword txl_keyword contained set-hash-userdata set-sig-handler sethash setitimer
-syn keyword txl_keyword contained setlogmask sh sig-abrt sig-alrm
-syn keyword txl_keyword contained sig-bus sig-check sig-chld sig-cont
-syn keyword txl_keyword contained sig-fpe sig-hup sig-ill sig-int
-syn keyword txl_keyword contained sig-io sig-iot sig-kill sig-lost
-syn keyword txl_keyword contained sig-pipe sig-poll sig-prof sig-pwr
-syn keyword txl_keyword contained sig-quit sig-segv sig-stkflt sig-stop
-syn keyword txl_keyword contained sig-sys sig-term sig-trap sig-tstp
-syn keyword txl_keyword contained sig-ttin sig-ttou sig-urg sig-usr1
-syn keyword txl_keyword contained sig-usr2 sig-vtalrm sig-winch sig-xcpu
-syn keyword txl_keyword contained sig-xfsz sin sixth size-vec
-syn keyword txl_keyword contained some sort source-loc source-loc-str
-syn keyword txl_keyword contained span-str splice split-str split-str-set
-syn keyword txl_keyword contained sqrt stat stdlib str<
-syn keyword txl_keyword contained str<= str= str> str>=
-syn keyword txl_keyword contained stream-get-prop stream-set-prop streamp string-extend
-syn keyword txl_keyword contained string-lt stringp sub sub-list
-syn keyword txl_keyword contained sub-str sub-vec symacrolet symbol-function
-syn keyword txl_keyword contained symbol-name symbol-package symbol-value symbolp
-syn keyword txl_keyword contained symlink sys-qquote sys-splice sys-unquote
-syn keyword txl_keyword contained syslog tan tf third
-syn keyword txl_keyword contained throw throwf time time-fields-local
-syn keyword txl_keyword contained time-fields-utc time-string-local time-string-utc time-usec
-syn keyword txl_keyword contained tofloat toint tok-str tok-where
-syn keyword txl_keyword contained tostring tostringp transpose tree-bind
-syn keyword txl_keyword contained tree-case tree-find trie-add trie-compress
-syn keyword txl_keyword contained trie-lookup-begin trie-lookup-feed-char trie-value-at trim-str
-syn keyword txl_keyword contained true trunc tuples typeof
-syn keyword txl_keyword contained unget-byte unget-char uniq unless
-syn keyword txl_keyword contained unquote until upcase-str update
-syn keyword txl_keyword contained url-decode url-encode usleep uw-protect
-syn keyword txl_keyword contained vec vec-push vec-set-length vecref
-syn keyword txl_keyword contained vector vector-list vectorp when
-syn keyword txl_keyword contained where while with-saved-vars zerop
-syn keyword txl_keyword contained zip
+syn keyword txl_keyword contained getpid getppid giterate greater
+syn keyword txl_keyword contained group-by gun hash hash-alist
+syn keyword txl_keyword contained hash-construct hash-count hash-diff hash-eql
+syn keyword txl_keyword contained hash-equal hash-isec hash-keys hash-pairs
+syn keyword txl_keyword contained hash-uni hash-update hash-update-1 hash-values
+syn keyword txl_keyword contained hashp html-decode html-encode iapply
+syn keyword txl_keyword contained identity ido if iff
+syn keyword txl_keyword contained iffi inc inhash int-flo
+syn keyword txl_keyword contained int-str integerp intern interp-fun-p
+syn keyword txl_keyword contained interpose ip ipf isqrt
+syn keyword txl_keyword contained itimer-prov itimer-real itimer-virtual juxt
+syn keyword txl_keyword contained keep-if keep-if* keywordp kill
+syn keyword txl_keyword contained labels lambda last lazy-str
+syn keyword txl_keyword contained lazy-str-force lazy-str-force-upto lazy-str-get-trailing-list lazy-stream-cons
+syn keyword txl_keyword contained lazy-stringp lbind lcons-fun lconsp
+syn keyword txl_keyword contained ldiff length length-list length-str
+syn keyword txl_keyword contained length-str-< length-str-<= length-str-> length-str->=
+syn keyword txl_keyword contained length-vec less let let*
+syn keyword txl_keyword contained link lisp-parse list list*
+syn keyword txl_keyword contained list-str list-vector listp log
+syn keyword txl_keyword contained log-alert log-auth log-authpriv log-cons
+syn keyword txl_keyword contained log-crit log-daemon log-debug log-emerg
+syn keyword txl_keyword contained log-err log-info log-ndelay log-notice
+syn keyword txl_keyword contained log-nowait log-odelay log-perror log-pid
+syn keyword txl_keyword contained log-user log-warning log10 log2
+syn keyword txl_keyword contained logand logior lognot logtest
+syn keyword txl_keyword contained logtrunc logxor macro-form-p macro-time
+syn keyword txl_keyword contained macroexpand macroexpand-1 macrolet major
+syn keyword txl_keyword contained make-catenated-stream make-env make-hash make-lazy-cons
+syn keyword txl_keyword contained make-like make-package make-random-state make-similar-hash
+syn keyword txl_keyword contained make-string-byte-input-stream make-string-input-stream make-string-output-stream make-strlist-output-stream
+syn keyword txl_keyword contained make-sym make-time make-time-utc make-trie
+syn keyword txl_keyword contained makedev mapcar mapcar* mapdo
+syn keyword txl_keyword contained maphash mappend mappend* mask
+syn keyword txl_keyword contained match-fun match-regex match-regex-right match-str
+syn keyword txl_keyword contained match-str-tree max member member-if
+syn keyword txl_keyword contained memq memql memqual merge
+syn keyword txl_keyword contained min minor mkdir mknod
+syn keyword txl_keyword contained mkstring mod multi multi-sort
+syn keyword txl_keyword contained n-choose-k n-perm-k nconc nilf
+syn keyword txl_keyword contained none not nreverse null
+syn keyword txl_keyword contained nullify num-chr num-str numberp
+syn keyword txl_keyword contained oddp op open-command open-directory
+syn keyword txl_keyword contained open-file open-files open-files* open-pipe
+syn keyword txl_keyword contained open-process open-tail openlog or
+syn keyword txl_keyword contained orf packagep partition partition*
+syn keyword txl_keyword contained partition-by perm pop pos
+syn keyword txl_keyword contained pos-if pos-max pos-min posq
+syn keyword txl_keyword contained posql posqual pprinl pprint
+syn keyword txl_keyword contained pprof prinl print prof
+syn keyword txl_keyword contained prog1 progn prop proper-listp
+syn keyword txl_keyword contained push pushhash put-byte put-char
+syn keyword txl_keyword contained put-line put-lines put-string put-strings
+syn keyword txl_keyword contained pwd qquote quasi quasilist
+syn keyword txl_keyword contained quote rand random random-fixnum
+syn keyword txl_keyword contained random-state-p range range* range-regex
+syn keyword txl_keyword contained rcomb read readlink real-time-stream-p
+syn keyword txl_keyword contained reduce-left reduce-right ref refset
+syn keyword txl_keyword contained regex-compile regex-parse regexp regsub
+syn keyword txl_keyword contained rehome-sym remhash remove-if remove-if*
+syn keyword txl_keyword contained remove-path remq remq* remql
+syn keyword txl_keyword contained remql* remqual remqual* rename-path
+syn keyword txl_keyword contained repeat replace replace-list replace-str
+syn keyword txl_keyword contained replace-vec rest ret retf
+syn keyword txl_keyword contained return return-from reverse rlcp
+syn keyword txl_keyword contained rperm rplaca rplacd run
+syn keyword txl_keyword contained s-ifblk s-ifchr s-ifdir s-ififo
+syn keyword txl_keyword contained s-iflnk s-ifmt s-ifreg s-ifsock
+syn keyword txl_keyword contained s-irgrp s-iroth s-irusr s-irwxg
+syn keyword txl_keyword contained s-irwxo s-irwxu s-isgid s-isuid
+syn keyword txl_keyword contained s-isvtx s-iwgrp s-iwoth s-iwusr
+syn keyword txl_keyword contained s-ixgrp s-ixoth s-ixusr search
+syn keyword txl_keyword contained search-regex search-str search-str-tree second
+syn keyword txl_keyword contained seek-stream select seqp set
+syn keyword txl_keyword contained set-diff set-hash-userdata set-sig-handler sethash
+syn keyword txl_keyword contained setitimer setlogmask sh sig-abrt
+syn keyword txl_keyword contained sig-alrm sig-bus sig-check sig-chld
+syn keyword txl_keyword contained sig-cont sig-fpe sig-hup sig-ill
+syn keyword txl_keyword contained sig-int sig-io sig-iot sig-kill
+syn keyword txl_keyword contained sig-lost sig-pipe sig-poll sig-prof
+syn keyword txl_keyword contained sig-pwr sig-quit sig-segv sig-stkflt
+syn keyword txl_keyword contained sig-stop sig-sys sig-term sig-trap
+syn keyword txl_keyword contained sig-tstp sig-ttin sig-ttou sig-urg
+syn keyword txl_keyword contained sig-usr1 sig-usr2 sig-vtalrm sig-winch
+syn keyword txl_keyword contained sig-xcpu sig-xfsz sin sixth
+syn keyword txl_keyword contained size-vec some sort source-loc
+syn keyword txl_keyword contained source-loc-str span-str splice split-str
+syn keyword txl_keyword contained split-str-set sqrt stat stdlib
+syn keyword txl_keyword contained str< str<= str= str>
+syn keyword txl_keyword contained str>= stream-get-prop stream-set-prop streamp
+syn keyword txl_keyword contained string-extend string-lt stringp sub
+syn keyword txl_keyword contained sub-list sub-str sub-vec symacrolet
+syn keyword txl_keyword contained symbol-function symbol-name symbol-package symbol-value
+syn keyword txl_keyword contained symbolp symlink sys-qquote sys-splice
+syn keyword txl_keyword contained sys-unquote syslog tan tf
+syn keyword txl_keyword contained third throw throwf time
+syn keyword txl_keyword contained time-fields-local time-fields-utc time-string-local time-string-utc
+syn keyword txl_keyword contained time-usec tofloat toint tok-str
+syn keyword txl_keyword contained tok-where tostring tostringp transpose
+syn keyword txl_keyword contained tree-bind tree-case tree-find trie-add
+syn keyword txl_keyword contained trie-compress trie-lookup-begin trie-lookup-feed-char trie-value-at
+syn keyword txl_keyword contained trim-str true trunc tuples
+syn keyword txl_keyword contained typeof unget-byte unget-char uniq
+syn keyword txl_keyword contained unless unquote until upcase-str
+syn keyword txl_keyword contained update url-decode url-encode usleep
+syn keyword txl_keyword contained uw-protect vec vec-push vec-set-length
+syn keyword txl_keyword contained vecref vector vector-list vectorp
+syn keyword txl_keyword contained when where while with-saved-vars
+syn keyword txl_keyword contained zerop zip
syn match txr_error "@[\t ]*[*]\?[\t ]*."
syn match txr_nested_error "[^\t `]\+" contained