euclid   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/pattern-language.xtm

Implementation

(define euclid
  (lambda (k n . args)
    (let ((one-val (if (null? args) 1 (car args)))
          (zero-val (if (< (length args) 2) '_ (cadr args))))
      (cond ((<= k 0) (repeat n zero-val))
            ((>= k n) (repeat n one-val))
            (else
             (let loop ((groups (euclid-distribute-zeros
                                 (list (repeat k (list one-val))
                                       (repeat (- n k) (list zero-val))))))
               (if (or (= (length groups) 1) (member (cadr groups) (list zero-val)))
                   (flatten groups)
                   (loop (euclid-distribute-zeros groups)))))))))


Back to Index

Similar Entries