Skip to content

Instantly share code, notes, and snippets.

@achim
Created July 1, 2009 01:49
Show Gist options
  • Save achim/138546 to your computer and use it in GitHub Desktop.
Save achim/138546 to your computer and use it in GitHub Desktop.
From 11d0bc951403f823df65c9d00fd4766873c65311 Mon Sep 17 00:00:00 2001
From: Achim Passen <achim.passen@gmail.com>
Date: Wed, 1 Jul 2009 03:45:44 +0200
Subject: [PATCH] Added [x &rest xs] binding form for lazier destructuring, added nthrest to core
---
src/clj/clojure/core.clj | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 38c58da..8adfb4c 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -2574,6 +2574,11 @@
(recur (dec n) (next xs))
xs)))
+(defn nthrest
+ "Returns the nth next of coll, coll when n is 0."
+ [coll n]
+ (nth (iterate rest coll) n))
+
;redefine let and loop with destructuring
(defn destructure [bindings]
@@ -2593,6 +2598,10 @@
n
(nnext bs)
true)
+ (= firstb '&rest) (recur (pb ret (second bs) (list `nthrest gvec n))
+ n
+ (nnext bs)
+ true)
(= firstb :as) (pb ret (second bs) gvec)
:else (if seen-rest?
(throw (new Exception "Unsupported binding form, only :as can follow & parameter"))
--
1.6.3.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment