mini cookbook

this is an informal place to post useful code snippets that don't warrant writing a chapter on the official cl-cookbook page

vectors

swap partitions within a vector

Pasted by: 	kreuter

(defun swap-partitions (sequence n) (let ((l (length sequence))) (psetf (subseq sequence 0 (- l n)) (subseq sequence n) (subseq sequence (- l n)) (subseq sequence 0 n))) sequence)

(loop for i upfrom 0 below 6 for v = (vector 1 2 3 4 5) do (print (swap-partitions v i)))

#(1 2 3 4 5) #(2 3 4 5 1) #(3 4 5 1 2) #(4 5 1 2 3) #(5 1 2 3 4) #(1 2 3 4 5) NIL


This page is presently Uncategorized: please add appropriate topic markers and remove this text

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively