NagyMusic Posted February 20 Share Posted February 20 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! Quote Link to comment Share on other sites More sharing options...
erka Posted February 20 Share Posted February 20 (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)) NagyMusic 1 Quote Link to comment Share on other sites More sharing options...
NagyMusic Posted February 20 Author Share Posted February 20 Thank you! Quote Link to comment Share on other sites More sharing options...
erka Posted March 5 Share Posted March 5 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) NagyMusic 1 Quote Link to comment Share on other sites More sharing options...
NagyMusic Posted March 5 Author Share Posted March 5 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) Quote Link to comment Share on other sites More sharing options...
erka Posted March 5 Share Posted March 5 (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 NagyMusic 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.