Cliff Posted October 25 Share Posted October 25 Beginner question. I intend to get from c dorian scale all possible triads except those with pitch classes 0 1. (setf scale (expand-tonality '(c4 dorian))) (setf scale-pcs (get-pcs scale)) (setf all-triads (pcs-sub-sets 3 scale-pcs)) (setf avoid (pcs-super-sets 3 '(0 1))) Basically I was looking for a setdiff function for both lists all-triads and avoid. Is there a function in OM for that? I tried myself, but my lisp knowledge is still insufficient to do the job. Any help? Quote Link to comment Share on other sites More sharing options...
Cliff Posted October 25 Author Share Posted October 25 I asked OM Chat-GPT: (setf result (set-difference all-triads avoid)) It seems correct opmo 1 Quote Link to comment Share on other sites More sharing options...
opmo Posted October 25 Share Posted October 25 Correct the set-difference function computes the difference between two sets represented as lists. It returns a new list containing elements from the first list (list1) that are not present in the second list (list2). This function is part of the Common Lisp standard and should behave consistently across compliant implementations. Stephane Boussuge and Cliff 2 Quote Link to comment Share on other sites More sharing options...
jon Posted October 26 Share Posted October 26 There is code (credited to Janusz) in Julio’s new OM book that achieves a similar goal. in the book, the goal is to get all the sets of cardinality 4 that don’t contain a (0 1 2) cluster as a subset. Interesting to see a different approach here. This version seems much simpler. Quote Link to comment Share on other sites More sharing options...
JulioHerrlein Posted October 27 Share Posted October 27 Yes, indeed very interesting ! Here is Janusz´s code you mentioned: (let ((out (pcs-cardinal 4 :forte))) ; search the supersets of Forte 3-1 (chromatic cluster) (loop for i in (pcs-super-sets 4 (pcs '3-1) :forte) ;remove supersets of Forte 3-1 (chromatic cluster) do (setf out (remove i out)) ;filtered result finally (return out))) Here is the same, with set-difference (reverse (set-difference (pcs-cardinal 4 :forte) (pcs-super-sets 4 (pcs '3-1) :forte))) All the best ! Julio Quote Link to comment Share on other sites More sharing options...
opmo Posted October 27 Share Posted October 27 This code demonstrates how to use the loop macro, an essential tool for many types of data manipulation. (let ((out (pcs-cardinal 4 :forte))) (loop for i in (pcs-super-sets 4 (pcs '3-1) :forte) do (setf out (remove i out)) finally (return out))) Understanding it will enable you to solve a wide range of conditional manipulations in the future. JulioHerrlein 1 Quote Link to comment Share on other sites More sharing options...
JulioHerrlein Posted Monday at 01:33 PM Share Posted Monday at 01:33 PM Dear Janusz, Exactly ! Your code is a much more open and useful for many different situations, showing the loop macro. Thanks a lot ! But set-difference is very interesting for list comparing. All the best ! 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.