Skip to content
View in the app

A better way to browse. Learn more.

Opusmodus Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Count Items In Sublists

Featured Replies

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!

 

 

(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))

  • Author

Thank you!

  • 2 weeks later...

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)

  • 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)

 

(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


© 2014-2026 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.