09.12.2012 Views

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Booleans<br />

Alternatively, you can place expressions to be evaluated within curly braces:<br />

#({2+5} #(abc))<br />

A boolean is one of two values: true or false. <strong>The</strong>re are two boolean literals:<br />

true<br />

and<br />

false<br />

Some examples of boolean expressions include:<br />

(2 + 2) = 5<br />

i >= 2<br />

Logical Operations<br />

Blocks<br />

aSet isEmpty<br />

file atEnd<br />

Boolean expressions can be combined using the logical operators AND and OR.<br />

<strong>The</strong>re are two different kinds of logical operations <strong>for</strong> both AND and OR. One type evaluates only as<br />

much of the expression as is necessary to determine whether the entire expression is true or false; in this<br />

type of expression, the second alternative is placed within a block, <strong>for</strong> example:<br />

anArray isEmpty or: [(anArray at: 1) = 0]<br />

aStream atEnd not and: [aStream next == ‘a’]<br />

<strong>The</strong> other type always evaluates both arguments of the expression; in this type of expression, the two arguments<br />

are separated by an ampersand <strong>for</strong> AND or a vertical bar <strong>for</strong> OR, <strong>for</strong> example:<br />

t > 2.5 & (t < 550.0)<br />

r next > 0.5 | (r next = 0.0)<br />

<strong>The</strong> following expression is true if anArray is empty or if its first entry is 0. If the first expression is true,<br />

then the expression within square brackets is not evaluated, since the entire expression is true if either of<br />

the subexpressions is true. By using this <strong>for</strong>m of the OR, you are protected against trying to access an<br />

empty array.<br />

anArray isEmpty or: [(anArray at: 1) = 0]<br />

In the next example, the OR operation is represented by a vertical bar. Both expressions are evaluated no<br />

matter what the value of the first expression. In this example, the message next returns the next value in a<br />

stream of values. It also has the side effect of advancing the pointer into the stream. In cases where an expression<br />

has a side-effect, you may want to evaluate both expressions even when the first is true.<br />

anArray isEmpty | (aStream next = 0)<br />

In the following example of the AND operator, the second expression is evaluated only if the first expression<br />

is true. In the case of this example, you wouldn’t want to try accessing the ith position of anArray<br />

unless you were sure that anArray had at least i positions in it.<br />

(anArray size >= i) and: [(anArray at: i) = 10]<br />

<strong>The</strong> ampersand operator is an AND in which both expressions are evaluated even if the first is false. In<br />

this particular case, the message removeFirst returns the first element of aCollection, but it also has<br />

the side effect of changing aCollection by removing the first element.<br />

i > 10 & (aCollection removeFirst = 0)<br />

A block is a deferred sequence of instructions having the <strong>for</strong>m<br />

518

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!