[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Partition for Emacs Lisp
From: |
Vassil Nikolov |
Subject: |
Re: Partition for Emacs Lisp |
Date: |
Sun, 28 Jun 2009 20:46:15 -0400 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
> On Jun 28, 6:26 am, Marc Tfardy <b...@cyk.cyk> wrote:
>> ...
>> (partition '(a b c d e f) 2)
>>
>> should return:
>> ((a b) (c d) (e f))
>>
>> Is there something ready out from the box?
(Define "out from the box"...)
(when (and (fboundp 'featurep) (featurep 'emacs)) ;seen in comp.lang.lisp
(require 'cl))
(defun partition (l n) ;"demo" grade, cursorily tested
"Return a list of L's consecutive sublists of length N."
(assert (zerop (mod (length l) n)))
(loop for l on l by #'(lambda (l) (nthcdr n l)) collect (subseq l 0 n)))
(partition '(a b c d e f) 2)
=> ((a b) (c d) (e f))
---Vassil.
--
Vassil Nikolov <vnikolov@pobox.com>
(1) M(Gauss);
(2) M(a) if M(b) and declared(b, M(a)),
where M(x) := "x is a mathematician".