AM Posted April 12, 2017 Share Posted April 12, 2017 ;;; 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.) ;; a bit advanced (gen-length-constant props 'h.) ;; crazy (gen-length-constant props 'h._e) lviklund and opmo 2 Quote Link to comment Share on other sites More sharing options...
opmo Posted April 13, 2017 Share Posted April 13, 2017 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)) AM 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.