Overview Clamps Packages CM Dictionary Clamps Dictionary Fomus
Next: amp->db , Previous: add-sfz-preset , Up: A , Home: Overview

Clamps Dictionary

all-permutations

Function

(all-permutations list &key (test #'eql) (max-length 10))

Get all permutations of list. Make sure to supply a test function in case the elements can't be compared with #'eql, otherwise the function will blow the stack. max-length is the maximum length of list accepted. This serves as a safety measure to avoid making the lisp process unresponsive due to an excessive number of permutations.

Arguments

list List of elements to be permuted.
:test Function to test for equality of elements in list.
:max-length Positive Integer denoting maximum length of list accepted.

Examples

(all-permutations (range 4))
;; => ((0 1 2 3) (0 1 3 2) (0 2 1 3) (0 2 3 1) (0 3 1 2) (0 3 2 1) (1 0 2 3)
;; (1 0 3 2) (1 2 0 3) (1 2 3 0) (1 3 0 2) (1 3 2 0) (2 0 1 3) (2 0 3 1)
;; (2 1 0 3) (2 1 3 0) (2 3 0 1) (2 3 1 0) (3 0 1 2) (3 0 2 1) (3 1 0 2)
;; (3 1 2 0) (3 2 0 1) (3 2 1 0))

(all-permutations (range 20))
;;
;; => Error: list to be permuted exceeds maximum length.

Author: Orm Finnendahl

Created: 2025-02-18 Di 12:58

Validate