[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/trie bbfecae 085/111: Do lexbind test at compile-time i
From: |
Stefan Monnier |
Subject: |
[elpa] externals/trie bbfecae 085/111: Do lexbind test at compile-time instead of load-time. |
Date: |
Mon, 14 Dec 2020 11:35:26 -0500 (EST) |
branch: externals/trie
commit bbfecaee914d834daadb7ca980c8cb36b1b27340
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Do lexbind test at compile-time instead of load-time.
---
trie.el | 122 +++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 63 insertions(+), 59 deletions(-)
diff --git a/trie.el b/trie.el
index dd310ca..e36e417 100644
--- a/trie.el
+++ b/trie.el
@@ -177,6 +177,68 @@
;;; ================================================================
;;; Internal utility functions and macros
+(defmacro trie--if-lexical-binding (then else)
+ "If lexical binding is in effect, evaluate THEN, otherwise ELSE."
+ (declare (indent 1) (debug t))
+ (if (let ((tempvar nil)
+ (f (let ((tempvar t)) (lambda () tempvar))))
+ tempvar ;; shut up "unused lexical variable" byte-compiler warning
+ (funcall f))
+ then else))
+
+
+;; wrap CMPFUN for use in a subtree
+(trie--if-lexical-binding
+ (defun trie--wrap-cmpfun (cmpfun)
+ (lambda (a b)
+ (setq a (trie--node-split a)
+ b (trie--node-split b))
+ (cond ((eq a trie--terminator)
+ (if (eq b trie--terminator) nil t))
+ ((eq b trie--terminator) nil)
+ (t (funcall cmpfun a b)))))
+ (defun trie--wrap-cmpfun (cmpfun)
+ `(lambda (a b)
+ (setq a (trie--node-split a)
+ b (trie--node-split b))
+ (cond ((eq a trie--terminator)
+ (if (eq b trie--terminator) nil t))
+ ((eq b trie--terminator) nil)
+ (t (,cmpfun a b))))))
+
+
+;; create equality function from trie comparison function
+(trie--if-lexical-binding
+ (defun trie--construct-equality-function (comparison-function)
+ (lambda (a b)
+ (not (or (funcall comparison-function a b)
+ (funcall comparison-function b a)))))
+ (defun trie--construct-equality-function (comparison-function)
+ `(lambda (a b)
+ (not (or (,comparison-function a b)
+ (,comparison-function b a))))))
+
+
+;; create Lewenstein rank function from trie comparison function
+(trie--if-lexical-binding
+ (defun trie--construct-Lewenstein-rankfun (comparison-function)
+ (let ((compfun (trie-construct-sortfun comparison-function)))
+ (lambda (a b)
+ (cond
+ ((< (nth 1 (car a)) (nth 1 (car b))) t)
+ ((> (nth 1 (car a)) (nth 1 (car b))) nil)
+ (t (funcall compfun (nth 0 (car a)) (nth 0 (car b))))))))
+ (defun trie--construct-Lewenstein-rankfun (comparison-function)
+ `(lambda (a b)
+ (cond
+ ((< (nth 1 (car a)) (nth 1 (car b))) t)
+ ((> (nth 1 (car a)) (nth 1 (car b))) nil)
+ (t ,(trie-construct-sortfun comparison-function)
+ (nth 0 (car a)) (nth 0 (car b)))))))
+
+
+
+
;;; ----------------------------------------------------------------
;;; Functions and macros for handling a trie.
@@ -232,64 +294,6 @@
transform-for-print transform-from-read print-form)
-(defmacro trie-lexical-binding-p ()
- "Return non-nil if lexical binding is in effect, nil otherwise."
- (let ((tempvar (make-symbol "x")))
- `(let ((,tempvar nil)
- (f (let ((,tempvar t)) (lambda () ,tempvar))))
- (funcall f))))
-
-
-;; wrap CMPFUN for use in a subtree
-(if (trie-lexical-binding-p)
- (defun trie--wrap-cmpfun (cmpfun)
- (lambda (a b)
- (setq a (trie--node-split a)
- b (trie--node-split b))
- (cond ((eq a trie--terminator)
- (if (eq b trie--terminator) nil t))
- ((eq b trie--terminator) nil)
- (t (funcall cmpfun a b)))))
- (defun trie--wrap-cmpfun (cmpfun)
- `(lambda (a b)
- (setq a (trie--node-split a)
- b (trie--node-split b))
- (cond ((eq a trie--terminator)
- (if (eq b trie--terminator) nil t))
- ((eq b trie--terminator) nil)
- (t (,cmpfun a b))))))
-
-
-;; create equality function from trie comparison function
-(if (trie-lexical-binding-p)
- (defun trie--construct-equality-function (comparison-function)
- (lambda (a b)
- (not (or (funcall comparison-function a b)
- (funcall comparison-function b a)))))
- (defun trie--construct-equality-function (comparison-function)
- `(lambda (a b)
- (not (or (,comparison-function a b)
- (,comparison-function b a))))))
-
-
-;; create Lewenstein rank function from trie comparison function
-(if (trie-lexical-binding-p)
- (defun trie--construct-Lewenstein-rankfun (comparison-function)
- (let ((compfun (trie-construct-sortfun comparison-function)))
- (lambda (a b)
- (cond
- ((< (nth 1 (car a)) (nth 1 (car b))) t)
- ((> (nth 1 (car a)) (nth 1 (car b))) nil)
- (t (funcall compfun (nth 0 (car a)) (nth 0 (car b))))))))
- (defun trie--construct-Lewenstein-rankfun (comparison-function)
- `(lambda (a b)
- (cond
- ((< (nth 1 (car a)) (nth 1 (car b))) t)
- ((> (nth 1 (car a)) (nth 1 (car b))) nil)
- (t ,(trie-construct-sortfun comparison-function)
- (nth 0 (car a)) (nth 0 (car b)))))))
-
-
;;; ----------------------------------------------------------------
@@ -626,7 +630,7 @@ functions must *never* bind any variables with names
commencing
(trie--node-subtree (trie--root trie))))
-(if (trie-lexical-binding-p)
+(trie--if-lexical-binding
(defun trie-construct-sortfun (cmpfun &optional reverse)
"Construct function to compare key sequences, based on a CMPFUN
that compares individual elements of the sequence. Order is
- [elpa] externals/trie 87d5786 102/111: Allow trie-fuzzy-match/complete to take lists of multiple prefixes/strings., (continued)
- [elpa] externals/trie 87d5786 102/111: Allow trie-fuzzy-match/complete to take lists of multiple prefixes/strings., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 71f8273 098/111: Significantly improve efficiency of trie-fuzzy-complete., Stefan Monnier, 2020/12/14
- [elpa] externals/trie c2b5e26 105/111: Myriad bug fixes and code refactoring in new fuzzy and ngram completion., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 63da3b1 111/111: * trie.el: Fix header which likely suffered a `M-q` accident, Stefan Monnier, 2020/12/14
- [elpa] externals/trie ff5e05f 040/111: Bumped copyright year, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 2281926 020/111: Minor code reformatting and rearrangement, Stefan Monnier, 2020/12/14
- [elpa] externals/trie d99fb00 055/111: Simplified advice-based edebug pretty-printing of tries and dictionaries., Stefan Monnier, 2020/12/14
- [elpa] externals/trie b4d81bf 064/111: Trivial whitespace tidying., Stefan Monnier, 2020/12/14
- [elpa] externals/trie d45e9d5 062/111: Added autoload cookies., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 1c2790d 038/111: Replaced wildcard searches with more powerful and efficient regexp searches., Stefan Monnier, 2020/12/14
- [elpa] externals/trie bbfecae 085/111: Do lexbind test at compile-time instead of load-time.,
Stefan Monnier <=
- [elpa] externals/trie 5e8e73f 081/111: Fix data wrapping handling in fuzzy query functions., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 2a9d7ec 099/111: Port efficiency improvements to trie-fuzzy-match., Stefan Monnier, 2020/12/14
- [elpa] externals/trie a2554d6 094/111: Fix function symbol quoting., Stefan Monnier, 2020/12/14
- [elpa] externals/trie c6ddbb9 096/111: Bump version numbers., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 94a1a86 087/111: Bump version numbers since we've added iterator generators., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 4001f61 097/111: Fix corresponding bug in trie-fuzzy-complete-stack., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 91d299c 104/111: Pretty-print trie nodes in edebug., Stefan Monnier, 2020/12/14
- [elpa] externals/trie fc9b218 032/111: Removed support for non-terminal * wildcards, Stefan Monnier, 2020/12/14
- [elpa] externals/trie 5a064c0 092/111: Fix bug in trie-delete return value., Stefan Monnier, 2020/12/14
- [elpa] externals/trie 9f49d95 086/111: Implement iterator generators on collection data structures., Stefan Monnier, 2020/12/14