OpenMusic

Visual Programming | Computer-Assisted Composition

OpenMusic Reference

Prev| | Next


omif

omif

(control module) -- returns action or else according to test

Syntax

omif test action &optional else

Inputs

name data type(s) comments
test any usually a predicate
action any  
else any optional; a value or patch to evaluate instead of action

Output

output data type(s) comments
first any  

Description

“If something then do this or else do that.

omif corresponds to the if-then-else construct found in most algebraic programming languages. A predicate is evaluated at the test input. In addition to the standard LISP truth value t, any value except nil is considered to be true. If it is true, then action is performed. Otherwise, nil is returned. Using the optional else argument allows this patch or function to be evaluated in place of returning nil in the case where test is nil.

Examples

Using omif to switch between possible outputs

In the example above, om-random will generate either a 1 or a zero. If it returns 1, then the om= function will return nil (since 1 does not equal 0) and omif will evaluate else , the third input, returning (gerard). If om-random returns 0 then om= will return t and omif will return action , its second input, (calros). Whatever the result, x-append will sandwich it between (hello) and (!). The two possible results are therefore:

? OM->(hello calros !)

and

? OM->(hello gerard !)


Prev Home Next
om-scale/sum Up omquantify