Command Expressions | [Topic] |
A number of Stella's commands evaluate "command expressions", or exprs, whose results are then processed by the command in some manner. For example, the set command evaluates exprs to return new slot values for the referenced objects. The map command evaluates exprs in the context of each referenced object to compute statistics that are displayed in an information table. A command expression may be as simple as a variable or slot name, or may involve complicated parenthetical expressions. Though exprs are evaluated and may involve Lisp's prefix notation, they are not strictly Lisp. Exprs implement a number of changes and additions to basic Lisp syntax in order to support a comfortable yet terse input style. For example, the simple command expression:
rhythmis roughly equivalent to the Lisp expression:
(or (and (slot-exists-p (mapped-object) 'rhythm) (slot-boundp (mapped-object) 'rhythm) (slot-value (mapped-object) 'rhythm) 0)Since command expressions are not strictly Lisp, they are only meaningful in conjunction with commands that understand their syntax and evaluation rules. These commands are: increment, invert, map, scale, set, transpose and unset. These commands are called mapping commands because they all map expressions over the references supplied to the command and evaluate each expressions in the context of each mapped object. The expressions rhythm, then, really means: "the value of the slot named rhythm in the currently mapped object, or 0 if that object has no rhythm." Note that when referencing by group there is no "currently mapped object" to speak of, since all members of a group are mapped in parallel. To access slot values and so fourth of an object within the currently mapped group, the access must be qualified with the object's index into the group. This index ranges from 1 to the width of the group, and is specified inside brackets after the basic name. For example:
Stella [Top-Level]: map :::2 find (= rhythm[1] rhythm[2])would perform a pairwise examination of all the objects in * and return the index of each pair of objects that have the same value in their rhythm slots.
Command expression syntax and evaluation rules
Here is a brief summary of the syntax and evaluation rules for command expressions.
Stella [Top-Level]: set * note (pitches c4 d e in random)would set the note slot of each object in * to successive pitches read from a random pitch stream.
Stella [Top-Level]: set * freq (interpl @ 0 220.0 40 440.0)would set the freq slot of the (presumably forty) objects in * to an interpolated value between 200.0 and 400.0 Hz. It is also possible to qualify @ and @+1 by a group index, for example, @[1] would mean the container position of the first element in the currently mapped group.
Stella [Top-Level]: set * freq (interpl % 0 220.0 100 440.0)would set the freq slot of the elements in * to an interpolated value between 200.0 and 400.0 Hz. It is possible to qualify % by a group index, for example, %[1] would mean the percentage position of the first element in the currently mapped group.
(@ object &optional container) (@+1 object &optional container) (% object &optional container) (? object slot &optional value)
See Also:
increment [Command], invert [Command], map [Command], scale [Command], set [Command], transpose [Command] unset [Command]