Topics
The lambda mode for function boxes.
Key Modules Used
mapcar,om-random,repeat-n,arithm-ser,dx->x
The Concept:
Patches and functions in OM have different states. We have already seen two of them (the
’lock’ state in Tutorial_1 and the ’eval once’ state in Tutorial 12 There are two others; here we introduce the lambda state (λ). Any OM patch or function can be put in lambda mode.
This state is used whenever a function calls another function as an argument, in order to apply this second function to some data. These are generally standard LISP functions such asfuncallormapcar. In this tutorial we’ll look at two instances of their use.
To put a patch in lambda state, bring up the ’lock’ mark (an X) by selecting it and hitting b.
Then click the X representing the lock twice. The X becomes a 1 and then a letter lambda, λ:
Now let’s look at our examples.
The Patch:
The first example
Themapcarfunction takes as a first argument another function and applies that function it to its other arguments. This called function at the first argument can have any number of inputs.
Sincemapcarpasses the elements of its inputs as arguments to this called function,mapcar must have as many additional inputs as there are arguments of the called function. These inputs must themselves take lists.mapcartakes one element from each list and passes the group to the elements of the called function. It does this with each successive element of all the lists until the shortest list is exhausted, collecting the results in a list.
You’ll notice that we’ve typed the function name, list, into the box given as first input to
In terms of the patch, this pedal is added by putting each midic of the scale into a list with the midic 6000 with the list function. It would be tedious to perform thelist function 7 times. It would be more work to write anomloopto do this. mapcardoes it all in one step.
We give it a list of chromatic midics and list of 6000s of the same length and tell it to apply thelistfunction to the pairs.
We use anarithm-serto create the scale and repeat-nto create the list of 6000s. The results of themapcarfunction are:
? OM->((6000 6100) (6000 6200) (6000 6300) (6000 6400) (6000 6500) (6000 6600) (6000 6700))
The Second Example
withomloop. It’s faster, however, to do it withmapcar. In this case, we want to add a random value to each element of thelduroutput of the Chord-seq.
So, we write a patch that will do this to a single number, and then send the patch in lambda mode tomapcar, secure in the knowledge thatmapcarwill apply it once to each element of the list at its other input(s). In this case we only need one input since we are modifying the elements of just one list.
In Tutorial 30, an arithmetic series was turned into a list of durations. This series is graphed here using a BPF:
Notice the more or less linear movement upward. (The roughness is a result of the small number of data points.) What if we messed around with the values just a little bit in a random way, generating a shape that, while still moving up, is les linear:
We drag the patch Tutorial_30 into a new patch and make an abstraction of it with a so that we don’t screw up the original patch. We open it and add an output, connecting it to the selfoutput of the Voice factory.
In order to access durations from a Voice object one must use a Chord-seq. Therefore, we will connect the output of the Tutorial_30 patch to the first input of a Chord-seq (B).
We build a red patch which takes an integer and adds a random value between -200 and 300:
We need to convert these durations into onsets withdx->x, butdx->xonly takes flat lists as input. So we useflatto make it acceptable todx->xand pass it to thelonsetinput of the Chord-seq, using thelegatoargument to make sure things sound goooood.
Evaluating this patch varies the onsets of the notes in a small random way each time. Try evaluating it several times, listening to the results.
Tutorial 35: funcall with Lambda Functions
Topics
Calling a random function usingfuncall.
Key Modules Used
funcall,omif,om-random,omloop
The Concept:
funcall is like a single-shot version of mapcar; it takes the lambda function at its first input and passes it whatever comes in at the other inputs. Like mapcar, it usually should have as many optional inputs as the lambda function it is calling. funcall allows you to call a function as you would evaluate any other data. Here, we use anomiffunction with a random outcome (thanks toom-randomand the predicateom=) to send oneo of two lambda functions tofuncall. Whichever one we choose,funcallwill apply it to the Chord at (G).
The Patch:
procedure of Tutorial 18, which will interpolate a series of notes between this Chord and another.
Let’s look at the loop at (D).
Inside is an abstraction of the patch from Tutorial 14, with an input and an output added:
The result will be that the Tutorial 14 process is carried out for each note of the chord.
The other possible function is an abstraction of the patch from Tutorial 18:
...modified to accept two Chords as input and perform the interpolation process on them as outlined in Tutorial 18.
Note: Note that the second Chord for the interpolation is coming in from outside the patch. This demonstrates that the functions in lambda mode can still take data at their inputs, provided that the inputs are not going to be acted upon by thefuncallor whatever is calling them. Remember how we said thatfuncallusually has to have as many optional inputs as the function it is calling?
Well, here is the exception. Ourfuncallhere has one optional input. (In addition to the mandatory first input.) The abstraction has two inputs! Butfuncallwill only pass data to the first one since it was only given one argument at its additional inputs. The leaves the second argument of the abstration free; in fact, we must pass something to it in order for it to function correctly in lambda mode. Try disconnecting the second input and see the error.