OpenMusic

Visual Programming | Computer-Assisted Composition

Navigation : Previous | Next

Count : Counting Items

** Count ** is a counter. Its internal value increases at each evaluation evaluated, if the input value is non nil.

Inputs and Outputs

Count has one default input and three outputs :

—|—

Examples

Counting the Items of a List

  1. Listloop returns each element of the list successively to count. These elements are non nil values.

  2. The first output of count adds 1 every time listloop returns an element.

  3. Once the enumeration of listloop is over, the final state of count is returned by Finally.

—|—

Counting Specific Items of a List

We will now apply count more specifically, to know how many strings a list contains among other types of items.

  1. Listloop enumerates the elements of a list.

  2. The stringp predicate returns true every time it evaluates a string.

  3. At each step of the loop, the first output of count is evaluated :

* if it gets a non nil value from stringp, it increments the value of the counter
* if it gets "nil", the value doesn't change.   4. The results returned by stringp and counter are gathered in a list and printed.
  1. The total number of strings, that is, the final state of counter is returned by Finally.

—|—

References :

Contents :

Navigation : Previous | Next