# get-proportions

## Recommended Posts

```;;; GETTING THE LENGTH-PROPORTIONS AS INTEGERS

(defun get-proportions (omn_seq &key (abs 'nil))
(let ((denoms))
(progn
(setf denoms (remove-duplicates
(loop for i in (omn :length omn_seq)
collect (denominator (abs i)))))
(loop for i in (omn :length omn_seq)
collect (if (equal abs 't)
(* (abs i) (apply 'lcm denoms))
(* i (apply 'lcm denoms)))))))

;; examples
(get-proportions '(-3q 3h_h. d3 mf))
(get-proportions '(5q 5q 5q 5q 5q -e -s t t -q))
(get-proportions '(5q 5q 5q 5q 5q -e -s t t -q) :abs t)
(get-proportions '(-e -t t t t t t t t t -s. -q))

;;; HOW TO USE

(setf rhy '(-3h 3q_5h. 5q 5q c4))
(setf props (get-proportions rhy :abs nil))

;;; you can use that for GEN-LENGTH-CONSTANT

;; ordinary
(gen-length-constant props 'w.)
(gen-length-constant props 'h.)
;; crazy
(gen-length-constant props 'h._e)```

##### Share on other sites

With nested lists:

```(defun get-proportions (sequence &key abs)
(do-verbose ("get-proportions")
(flet ((get-proportions-l (sequence &key abs)
(let* ((length (omn-length sequence))
(den (remove-duplicates
(loop for i in length
collect (denominator (abs i)))
:from-end t)))
(loop for i in length
collect (if abs (* (abs i) (apply #'lcm den))
(* i (apply #'lcm den)))))))
(if (listsp sequence)
(loop for i in sequence
collect (get-proportions-l i :abs abs))
(get-proportions-l sequence :abs abs)))))

(get-proportions '(5q 5q 5q 5q 5q -e -s t t -q))
=> (8 8 8 8 8 -20 -10 5 5 -40)

(get-proportions '((-e -t t t t) (t t t t t -s. -q)))
=> ((-4 -1 1 1 1) (1 1 1 1 1 -3 -8))```

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• Lessons