February 20, 20233 yr Is there an Opusmodus function that counts the number of items in each sublist? '((c4 d4 e4) (f4 g4) (a4) (b4 c5)) => (3 2 1 2) Thanks!
February 20, 20233 yr (mapcar 'length '((c4 d4 e4) (f4 g4) (a4) (b4 c5))) Applies a function (first argument) to each element of a list. does the same as (loop for subl in '((c4 d4 e4) (f4 g4) (a4) (b4 c5)) collect (length subl))
March 5, 20233 yr I just learned from your post on another topic that there is a opusmodus-function "get-count". mapcar and loop works, but "get-count" is much more flexible for opusmodus. So as I learned from you, that is actually the right answer to the topic-question: get-count . Just want to mention it so when someone sees the topic will get the right answer and not my previous half answer. (and there is also mclength to be found under opusmodus functions)
March 5, 20233 yr Author Thanks, Erka. So using get-count, my above example would produce the same result as mapcar: (get-count '((c4 d4 e4) (f4 g4) (a4) (b4 c5)) :length :note)
March 5, 20233 yr (get-count '((c4 d4 e4) (f4 g4) (a4) (b4 c5)) ) would be the same as the mapcar or mclength . With :length option of get-count you can specify if you only want to count notes or rests. In this case :length :note would give the same result. There are good examples in the docs of get-count. You used it in your pedal related post: (setf counts-notes (get-count (omn :pitch mat))). (get-count '((c4 d4 e4) (f4 g4) (a4) (b4 c5)) ) (mapcar 'length '((c4 d4 e4) (f4 g4) (a4) (b4 c5))). ;That is basic from a LISP-view without knowing opusmodus. (mclength '((c4 d4 e4) (f4 g4) (a4) (b4 c5))) all return => (3 2 1 2) Have a nice Sunday Rolf
Create an account or sign in to comment