[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 12ed9f6 100/426: Add destructive operations !cons
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 12ed9f6 100/426: Add destructive operations !cons og !cdr |
Date: |
Tue, 04 Aug 2015 19:36:59 +0000 |
branch: externals/dash
commit 12ed9f6622f66daffeb0c23d5497cd2933333225
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add destructive operations !cons og !cdr
---
README.md | 20 ++++++++++++++++++++
dash.el | 8 ++++++++
examples.el | 8 ++++++++
3 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 419955b..1c309e5 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,8 @@ Or you can just dump `dash.el` in your load path somewhere.
* [->](#--x-optional-form-rest-more) `(x &optional form &rest more)`
* [->>](#--x-form-rest-more) `(x form &rest more)`
* [-->](#---x-form-rest-more) `(x form &rest more)`
+* [!cons](#-cons-car-cdr) `(car cdr)`
+* [!cdr](#-cdr-list) `(list)`
There are also anaphoric versions of these functions where that makes sense,
prefixed with two dashes instead of one.
@@ -461,6 +463,24 @@ in in second form, etc.
(--> "def" (concat "abc" it "ghi") upcase) ;; => "ABCDEFGHI"
```
+### !cons `(car cdr)`
+
+Destructive: Sets `cdr` to the cons of `car` and `cdr`.
+
+```cl
+(let (l) (!cons 5 l) l) ;; => '(5)
+(let ((l '(3))) (!cons 5 l) l) ;; => '(5 3)
+```
+
+### !cdr `(list)`
+
+Destructive: Sets `list` to the cdr of `list`.
+
+```cl
+(let ((l '(3))) (!cdr l) l) ;; => '()
+(let ((l '(3 5))) (!cdr l) l) ;; => '(5)
+```
+
## Development
diff --git a/dash.el b/dash.el
index a115338..2756529 100644
--- a/dash.el
+++ b/dash.el
@@ -27,6 +27,14 @@
;;; Code:
+(defmacro !cons (car cdr)
+ "Destructive: Sets CDR to the cons of CAR and CDR."
+ `(setq ,cdr (cons ,car ,cdr)))
+
+(defmacro !cdr (list)
+ "Destructive: Sets LIST to the cdr of LIST."
+ `(setq ,list (cdr ,list)))
+
(defun -map (fn list)
"Returns a new list consisting of the result of applying FN to the items in
LIST."
(mapcar fn list))
diff --git a/examples.el b/examples.el
index 1c8211a..bbe5654 100644
--- a/examples.el
+++ b/examples.el
@@ -189,3 +189,11 @@
(--> "def" (concat "abc" it "ghi")) => "abcdefghi"
(--> "def" (concat "abc" it "ghi") (upcase it)) => "ABCDEFGHI"
(--> "def" (concat "abc" it "ghi") upcase) => "ABCDEFGHI")
+
+(defexamples !cons
+ (let (l) (!cons 5 l) l) => '(5)
+ (let ((l '(3))) (!cons 5 l) l) => '(5 3))
+
+(defexamples !cdr
+ (let ((l '(3))) (!cdr l) l) => '()
+ (let ((l '(3 5))) (!cdr l) l) => '(5))
- [elpa] externals/dash c56925a 111/426: Add font-lock for new functions and the `it` token., (continued)
- [elpa] externals/dash c56925a 111/426: Add font-lock for new functions and the `it` token., Phillip Lord, 2015/08/04
- [elpa] externals/dash a081c72 114/426: Fix tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash a336d78 112/426: Add -only-some?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 81a3247 104/426: Let -each and -each-while take multiple forms., Phillip Lord, 2015/08/04
- [elpa] externals/dash d857f73 118/426: Merge pull request #3 from rejeep/join-alias, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9faa422 115/426: Add -partition-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash f034c16 119/426: Add -union (thanks to @Fuco1), Phillip Lord, 2015/08/04
- [elpa] externals/dash 9a3dfdd 113/426: Name parameter PRED when function expects predicate., Phillip Lord, 2015/08/04
- [elpa] externals/dash cca9b1b 121/426: Also run tests on Emacs24, Phillip Lord, 2015/08/04
- [elpa] externals/dash c669282 123/426: Add @Fuco1 to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 12ed9f6 100/426: Add destructive operations !cons og !cdr,
Phillip Lord <=
- [elpa] externals/dash c025efb 122/426: Add -separate (thanks @Fuco1), Phillip Lord, 2015/08/04
- [elpa] externals/dash 2c5b86e 117/426: Add -join as alias to -distinct., Phillip Lord, 2015/08/04
- [elpa] externals/dash 1c4e5d7 125/426: Remove eval from --reduce, it is evil., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8f91ec8 126/426: 1.0.2, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1120417 127/426: Add -group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5e72ff9 120/426: Include numbers in github ids., Phillip Lord, 2015/08/04
- [elpa] externals/dash a23aa4b 128/426: Add examples for -group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7f7ac33 130/426: Add Takafumi Arakaki to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 3044e83 129/426: Merge pull request #8 from tkf/group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 85bd4e0 131/426: Add @tali713's -applify, Phillip Lord, 2015/08/04