[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/relint c215d54 34/44: More careful evaluation of if, wh
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/relint c215d54 34/44: More careful evaluation of if, when, unless, and, or |
Date: |
Tue, 26 Mar 2019 12:57:30 -0400 (EDT) |
branch: externals/relint
commit c215d54fa2bde02bb9508ff316078d97120fec7a
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
More careful evaluation of if, when, unless, and, or
---
relint.el | 53 +++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 45 insertions(+), 8 deletions(-)
diff --git a/relint.el b/relint.el
index 0147bf0..e13af44 100644
--- a/relint.el
+++ b/relint.el
@@ -344,15 +344,52 @@
(error 'no-value))
'no-value)))
- ;; if, when, unless, and, or: Treat these as functions and eval all args.
- ((memq (car form) '(if when unless and or))
- (let ((args (mapcar #'relint--eval (cdr form))))
- (if (memq 'no-value args)
+ ;; if: evaluate condition and the right branch.
+ ((eq (car form) 'if)
+ (let ((condition (relint--eval (cadr form))))
+ (if (eq condition 'no-value)
'no-value
- ;; eval is safe here: all args are quoted constants.
- (eval (cons (car form)
- (mapcar (lambda (x) (list 'quote x)) args))))))
-
+ (let ((then-part (nth 2 form))
+ (else-tail (nthcdr 3 form)))
+ (cond (condition
+ (relint--eval then-part))
+ ((and else-tail (cdr else-tail))
+ 'no-value) ; Ignore multi-value else bodies.
+ (else-tail
+ (relint--eval (car else-tail))))))))
+
+ ;; when, unless: evaluate condition and maybe consequent.
+ ((memq (car form) '(when unless))
+ (let ((condition (relint--eval (cadr form)))
+ (body (cddr form)))
+ (cond ((or (eq condition 'no-value)
+ (not (= (length body) 1)))
+ 'no-value)
+ ((eq (not condition) (eq (car form) 'unless))
+ (relint--eval (car body))))))
+
+ ;; and: keep evaluating until false or empty.
+ ((eq (car form) 'and)
+ (if (cdr form)
+ (let ((val (relint--eval (cadr form))))
+ (if (eq val 'no-value)
+ 'no-value
+ (if (and val (cddr form))
+ (relint--eval (cons 'and (cddr form)))
+ val)))
+ t))
+
+ ;; and: keep evaluating until true or empty.
+ ((eq (car form) 'or)
+ (if (cdr form)
+ (let ((val (relint--eval (cadr form))))
+ (if (eq val 'no-value)
+ 'no-value
+ (if (and (not val) (cddr form))
+ (relint--eval (cons 'or (cddr form)))
+ val)))
+ nil))
+
((assq (car form) relint--safe-alternatives)
(relint--eval (cons (cdr (assq (car form) relint--safe-alternatives))
(cdr form))))
- [elpa] externals/relint ee70350 44/44: FSF copyright, URL, and increment version to 1.5, (continued)
- [elpa] externals/relint ee70350 44/44: FSF copyright, URL, and increment version to 1.5, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 0fd1d46 29/44: Rename trawl to relint, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint e882b71 42/44: Detect regexps spliced into [...], Mattias Engdegård, 2019/03/26
- [elpa] externals/relint c1b92cc 36/44: Wrap and evaluate defined functions passed as parameters, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint d4a6d46 37/44: Evaluate some more functions, macros and special forms, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 019f4cf 10/44: Rewrite the partial evaluator and extend coverage, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 365dc91 41/44: Check bad skip-set provenance, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint a1829d7 39/44: Refactor the file scanning and linting code, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 0f76132 40/44: Add README.org, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint e824db0 38/44: Expand locally defined macros, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint c215d54 34/44: More careful evaluation of if, when, unless, and, or,
Mattias Engdegård <=
- [elpa] externals/relint 15c799e 35/44: Evaluate calls to functions defined in the same file., Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 2d1f488 32/44: mapcar on non-list sequence, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint af745bb 30/44: Update the package description. Increment version to 1.4, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint e1b1ef9 22/44: Run in two phases on each file, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 7a1b632 33/44: Add wildcard-to-regexp as 'pure' function, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint f6fb8e6 31/44: Sundry cosmetic fixes, Mattias Engdegård, 2019/03/26
- [elpa] externals/relint 151dbb8 23/44: Handle some destructive list functions, Mattias Engdegård, 2019/03/26
- [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