Recherche Google
OpenMusic 6 – User ManualAdvanced Visual Programming > Control Structures > Predicates > Type Predicates
previous pagenext page

Type Predicates

A type predicate tests if an object belongs to a type of object . Most of these types are Lisp types, which can be found in the Classes of the OMKernel / Lisp package, or added in patches via data boxes.

Type predicates are not available in the OM menus or packages, but their name can be typed in a patch editor directly. It conventionally ends in the letter "p" for "predicate".

Numbers

There are several number types, which can be tested by the following predicates.

  • numberp : numbers
  • integerp : integer numbers
  • rationalp : rational numbers
  • floatp : decimal numbers

By extension, other predicates test the properties of numbers.

  • plusp : positive numbers
  • minusp : negative numbers
  • zerop : zero
  • evenp : even integers
  • oddp : odd integers

Main Other Type Predicates

Here are some of the most frequently used type predicates in OM :

Predicate

Returns "t" for

Example

characterp

the name of a character that has a printable glyph.

#\Space ; #\a ... -> t

symbolp

something that can be named but numbers, strings, lists, some characters.

'cow ; note ; 2-ERz -> t

atom

anything not between parenthesis but strings.

A ; 38 ; -> t

listp

anything between parenthesis, or nil. In Lisp, nil = empty list.

(A B C) ; (A (B C) -> t

consp

a list with a car1 and a cdr 1 .

(A B) ; (A (B C)) -> t

(A) -> nil

stringp

anything between inverted commas.

"vangogh#\Tab;;2" -> t

functionp

function names and function boxes on "lambda" mode.

-> t

nullp

anything that is nil.

nil -> t ; ( ) -> t

typep

an object of a given type.

  1. CAR, CDR, CADR, CDDR, CADDR...

    Elementary Lisp functions, allowing the access to one or more elements in a list. CAR and CDR are kernel functions upon which have been defined the rest of these functions.

    Let the following list be : (A B C D).

    CAR (A B C D) = A.

    CDR (A B C D) = (B C D).

    CADR (A B C D) = B. CADR means CAR of the CDR.

    CDDR (A B C D) = (C D). CDDR means CDR of the CDR.

    CADDR (A B C D) = C. CADDR means CAR of the CDDR.

    NTHCDR (A B C D) = NTH CDR of the list – N must be specified as argument. NTHCDR 3 (A B C D) = (D).

    And so on...

previous pagenext page
About...(c) Ircam - Centre PompidouMade with Scenari