[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master c30e4e1: Add new pattern type `de-morgan'
From: |
Michael Heerdegen |
Subject: |
[elpa] master c30e4e1: Add new pattern type `de-morgan' |
Date: |
Sat, 15 Apr 2017 11:30:40 -0400 (EDT) |
branch: master
commit c30e4e18f07acced61ff927627baba984a7845d2
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>
Add new pattern type `de-morgan'
Add pattern `de-morgan' which allows to simplify expressions by
applying de Morgan's law.
---
packages/el-search/el-search-x.el | 43 ++++++++++++++++++++++++++++++++++++++-
packages/el-search/el-search.el | 5 ++++-
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/packages/el-search/el-search-x.el
b/packages/el-search/el-search-x.el
index ef11c3d..5164c0f 100644
--- a/packages/el-search/el-search-x.el
+++ b/packages/el-search/el-search-x.el
@@ -374,7 +374,48 @@ expression matching the `change' pattern will be matched."
'(outermost _))
-;;; Patterns for stylistic rewriting
+;;; Patterns for stylistic rewriting and syntactical simplification
+
+;;; de Morgan
+
+(el-search-defpattern de-morgan (&optional replacement)
+ "Matches forms that can be simplified by applying de Morgan.
+Matched are all expressions of the form
+
+ (or (not A1) (not A2) ...)
+
+and
+
+ (and (not B1) (not B2) ...)
+
+where at least two `not' expressions are present.
+
+REPLACEMENT, when specified, should be a variable, and will be
+bound to a semantically equivalent expression with de Morgan's
+law been applied, namely
+
+ (not (and A1 A2 ...))
+
+or
+
+ (not (or B1 B2 ...))
+
+respectively.
+
+Note that when `el-search-query-replace'ing with this pattern
+type, it's possible that de Morgan can be applied again, so you
+may want to check that."
+ (let ((functor (make-symbol "functor"))
+ (nots (make-symbol "nots"))
+ (arg (make-symbol "arg")))
+ `(and `(,(and (or 'or 'and) ,functor) . ,,nots)
+ (guard (and (consp ,nots) (not (cdr (last ,nots))))) ;check for a
proper non-empty list
+ (guard (cl-every (lambda (,arg) (pcase ,arg (`(not ,_) t))) ,nots))
+ (let (pred identity) (cdr ,nots))
+ ,@(and replacement
+ (not (eq '_ replacement))
+ `((let ,replacement `(not (,(if (eq ,functor 'or) 'and 'or)
+ ,@(mapcar #'cadr ,nots)))))))))
;;;; Iffy `if's
diff --git a/packages/el-search/el-search.el b/packages/el-search/el-search.el
index aa8d464..cb2c0f7 100644
--- a/packages/el-search/el-search.el
+++ b/packages/el-search/el-search.el
@@ -7,7 +7,7 @@
;; Created: 29 Jul 2015
;; Keywords: lisp
;; Compatibility: GNU Emacs 25
-;; Version: 1.3
+;; Version: 1.3.1
;; Package-Requires: ((emacs "25") (stream "2.2.3"))
@@ -27,6 +27,9 @@
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+;; Dedicated to my Grandfather Fritz
+
+
;;; Commentary:
;; This package implements an expression based interactive search tool
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] master c30e4e1: Add new pattern type `de-morgan',
Michael Heerdegen <=