emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash 302c8ea 001/439: Initial commit.


From: Phillip Lord
Subject: [elpa] externals/dash 302c8ea 001/439: Initial commit.
Date: Tue, 04 Aug 2015 20:25:38 +0000

branch: externals/dash
commit 302c8ea0668b9f7653d7bedfbe69d02fc95b80a7
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Initial commit.
---
 README.md |   32 ++++++++++++++++++++
 bang.el   |   97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..88f07be
--- /dev/null
+++ b/README.md
@@ -0,0 +1,32 @@
+# bang.el
+
+The startings of a modern list api for Emacs.
+
+We're looking to Clojure for naming and signatures.
+
+Right now it relies on `cl` which should be one of the very first things we 
fix.
+
+## Warning
+
+This is so much a work in progress that you should definitely not be using it 
yet.
+
+## License
+
+;; Copyright (C) 2012 Magnar Sveen, Joel McCracken
+
+;; Authors: Magnar Sveen <address@hidden>
+;;          Joel McCracken
+;; Keywords: lists
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
diff --git a/bang.el b/bang.el
new file mode 100644
index 0000000..b1bd793
--- /dev/null
+++ b/bang.el
@@ -0,0 +1,97 @@
+;;; bang.el --- A modern list library for Emacs
+
+;; Copyright (C) 2012 Magnar Sveen, Joel McCracken
+
+;; Authors: Magnar Sveen <address@hidden>
+;;          Joel McCracken
+;; Keywords: lists
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; The startings of a modern list api for Emacs.
+
+;;; Code:
+
+(eval-when-compile (require 'cl))
+
+(defvar !compare-fn nil
+  "Tests for equality use this function or `equal' if this is nil.
+It should only be set using dynamic scope with a let, like:
+(let ((!compare-fn =)) (!union numbers1 numbers2 numbers3)")
+
+(defun !concat (list)
+  (apply 'concatenate 'list list))
+
+(defalias '!map 'mapcar)
+
+(defalias '!filter 'remove-if-not)
+(defalias '!select 'remove-if-not)
+(defalias '!reject 'remove-if)
+
+(defalias '!partial 'apply-partially)
+
+(defun !mapcat (fn list)
+  (!concat (!map fn list)))
+
+(defun !uniq (list)
+  "Return a new list with all duplicates removed.
+The test for equality is done with `equal',
+or with `!compare-fn' if that's non-nil."
+  (let (result)
+    (while list
+      (add-to-list 'result (car list) nil !compare-fn)
+      (setq list (cdr list)))
+    (reverse result)))
+
+(defun !intersection (list list2)
+  "Return a new list containing only the elements that are members of both 
LIST and LIST2.
+The test for equality is done with `equal',
+or with `!compare-fn' if that's non-nil."
+  (let (result)
+    (while list
+      (when (!contains-p list2 (car list))
+        (setq result (cons (car list) result)))
+      (setq list (cdr list)))
+    (reverse result)))
+
+(defun !difference (list list2)
+  "Return a new list with only the members of LIST that are not in LIST2.
+The test for equality is done with `equal',
+or with `!compare-fn' if that's non-nil."
+  (let (result)
+    (while list
+      (unless (!contains-p list2 (car list))
+        (setq result (cons (car list) result)))
+      (setq list (cdr list)))
+    (reverse result)))
+
+(defun !contains-p (list element)
+  "Return whether LIST contains ELEMENT.
+The test for equality is done with `equal',
+or with `!compare-fn' if that's non-nil."
+  (cond
+   ((null !compare-fn)    (member element list))
+   ((eq !compare-fn 'eq)  (memq element list))
+   ((eq !compare-fn 'eql) (memql element list))
+   (t
+    (let ((lst list))
+      (while (and lst
+                  (not (funcall !compare-fn element (car lst))))
+        (setq lst (cdr lst)))
+      lst))))
+
+(provide 'bang)
+;;; bang.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]