branch: externals/dash commit 2cc124b9576e82db2803b967e19c76dc418a8609 Author: Matus Goljer <dota.k...@gmail.com> Commit: Matus Goljer <dota.k...@gmail.com>
[-let] Generate better code when skipping conses --- dash.el | 5 ++--- dev/examples.el | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dash.el b/dash.el index b8822ac..d2c2b4d 100644 --- a/dash.el +++ b/dash.el @@ -1237,9 +1237,8 @@ All returned symbols are guaranteed to be unique." ((= skip-cdr 0) `(pop ,source)) (t - `(progn - (setq ,source (nthcdr ,skip-cdr ,source)) - (pop ,source))))) + `(prog1 ,(dash--match-cons-get-car skip-cdr source) + (setq ,source ,(dash--match-cons-get-cdr (1+ skip-cdr) source)))))) (defun dash--match-cons-get-car (skip-cdr source) "Helper function generating idiomatic code to get nth car." diff --git a/dev/examples.el b/dev/examples.el index 14835ee..b32d5c5 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -817,6 +817,10 @@ new list." (-let [(_ _ _ a) (list 1 2 3 4 5)] a) => 4 (-let [(_ _ _ (a b)) (list 1 2 3 (list 4 5))] (list a b)) => '(4 5) (-let [(_ a _ b) (list 1 2 3 4 5)] (list a b)) => '(2 4) + (-let [(_ a _ b _ c) (list 1 2 3 4 5 6)] (list a b c)) => '(2 4 6) + (-let [(_ a _ b _ _ _ c) (list 1 2 3 4 5 6 7 8)] (list a b c)) => '(2 4 8) + (-let [(_ a _ _ _ b _ c) (list 1 2 3 4 5 6 7 8)] (list a b c)) => '(2 6 8) + (-let [(_ _ _ a _ _ _ b _ _ _ c) (list 1 2 3 4 5 6 7 8 9 10 11 12)] (list a b c)) => '(4 8 12) (-let [(_ (a b) _ c) (list 1 (list 2 3) 4 5)] (list a b c)) => '(2 3 5) (-let [(_ (a b) _ . c) (list 1 (list 2 3) 4 5)] (list a b c)) => '(2 3 (5)) (-let [(_ (a b) _ (c d)) (list 1 (list 2 3) 4 (list 5 6))] (list a b c d)) => '(2 3 5 6)