[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint 02bf0ba 21/44: Use explicit list of pure functio
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint 02bf0ba 21/44: Use explicit list of pure functions |
Date: |
Tue, 26 Mar 2019 12:57:27 -0400 (EDT) |
branch: externals/relint
commit 02bf0ba01743a45b9a7d3a993d66c43fa62b6c4e
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Use explicit list of pure functions
Instead of relying on the `side-effect-free' property, which is set
by the byte-compiler and not necessarily available in batch mode,
use our own list. We had to add some functions anyway.
---
trawl.el | 55 ++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 19 deletions(-)
diff --git a/trawl.el b/trawl.el
index 12f5c36..809ca72 100644
--- a/trawl.el
+++ b/trawl.el
@@ -152,6 +152,39 @@
;; The names map to a list of the regexp argument indices.
(defvar trawl--regexp-functions)
+;; Functions that are safe to call during evaluation.
+;; With some exceptions (noted), these are pure.
+;; More functions could be added if there is evidence that it would
+;; help in evaluating more regexp strings.
+(defconst trawl--safe-functions
+ '(cons list append
+ concat
+ car cdr caar cadr cdar cddr car-safe cdr-safe nth nthcdr
+ format format-message
+ regexp-quote regexp-opt regexp-opt-charset
+ reverse
+ member memq remove remq
+ assoc assq rassoc rassq
+ identity
+ string make-string make-list
+ substring
+ length safe-length
+ symbol-name
+ null not
+ eq eql equal
+ string-equal string= string< string-lessp char-equal string-match-p
+ string-match ; Alters the match state.
+ vector aref elt vconcat
+ char-to-string string-to-char
+ number-to-string string-to-number int-to-string
+ upcase downcase capitalize
+ purecopy copy-sequence copy-alist
+ plist-get plist-member
+ consp atom stringp symbolp listp nlisp
+ integerp numberp natnump fixnump bignump characterp
+ sequencep vectorp arrayp
+ + - * / % mod 1+ 1- max min < <= = > >= /= abs))
+
;; Transform FORM into an expression that is safe to evaluate with the
;; bindings in trawl--variables and parameters in PARAMS.
;; Return the transformed expression with known variables substituted away,
@@ -184,11 +217,8 @@
(cond
;; Functions (and some special forms/macros) considered safe.
((symbolp f)
- (and (or (and (get f 'side-effect-free)
- (not (eq f 'symbol-value)))
- (memq f '(caar cadr cdar cddr purecopy remove remq
- if unless when and or
- regexp-opt regexp-opt-charset)))
+ (and (or (memq f trawl--safe-functions)
+ (memq f '(if when unless and or)))
f))
((atom f) nil)
((eq (car f) 'function)
@@ -257,20 +287,7 @@
form)
;; Reasonably pure functions: only call if all args can be fully evaluated.
- ((or (and (get (car form) 'side-effect-free)
- ;; Exceptions: there should probably be more.
- ;; Maybe we should just list the ones we believe are safe,
- ;; and not use side-effect-free?
- (not (eq (car form) 'symbol-value)))
- ;; Common functions that aren't marked as side-effect-free.
- (memq (car form) '(caar cadr cdar cddr
- regexp-opt regexp-opt-charset
- ;; alters last-coding-system-used
- decode-coding-string
- format-message format-spec
- purecopy remove remq
- ;; alters match state
- string-match string-match-p)))
+ ((memq (car form) trawl--safe-functions)
(let ((args (mapcar #'trawl--eval (cdr form))))
(if (memq 'no-value args)
'no-value
- [elpa] externals/relint 187d586 27/44: Scan arguments to `skip-chars-{forward, backward}', (continued)
- [elpa] externals/relint 187d586 27/44: Scan arguments to `skip-chars-{forward, backward}', Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 5af5466 26/44: Scan string-trim arguments, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 4dbcad9 24/44: Increment version to 1.2, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 104e66c 15/44: Fix bugs in evaluation of `rx' and `rx-to-strings', Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 3f8509a 13/44: Add more functions to check for regexp arguments, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint f8878ca 16/44: Report rx errors in the result buffer, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 8e37762 18/44: Protect against improper lists in function calls, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 66522ca 12/44: Increment version to 1.1, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 683f31b 28/44: Increment version to 1.3, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint ac5d0cf 25/44: Add more safe functions, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 02bf0ba 21/44: Use explicit list of pure functions,
Mattias Engdegård <=
- [elpa] externals/relint 7d0e177 20/44: Rewrite the higher-order function handling, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint be3979a 19/44: Check TRIM argument of `split-string' as well, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 5143edf 17/44: Fix indentation accidents, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d6320f9 14/44: Detect functions with regexp arguments, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d19133e 09/44: Better variable name patterns, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d4d8f97 11/44: Eval mapcar and mapcan with partial-evaluated lists, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 34304b4 08/44: Add (provides) line to make file importable, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 62ca3d4 05/44: Slight performance improvement, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 6ab713e 07/44: Reinstate erroneously removed line, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint cb1fdc5 06/44: Add caret pointing out the error in the quoted regexp, Mattias Engdegård, 2019/03/26