PLx suite:
Filter:
Tutorials (extension) | Libraries > miSCellaneous > PLx suite | Streams-Patterns-Events

PLx suite
ExtensionExtension

dynamic scope Pattern variants

Description

Environmental variables within functions can act as placeholders for values, but also Patterns itself. So Patterns including functional code (e.g. Pfunc, Plazy, Pcollect) can, thanks to dynamic scoping, turn into different Streams, depending on the environment where streamifying happens ( Event patterns and Functions ). This can be used for getting a whole parametrized family of Streams / EventStreamPlayers from a single pattern definition. Other applications are on-the-fly replacements and gui control of parameters of Pbinds / EventStreamPlayers with VarGui . Nevertheless constructs with Plazy, Pfunc etc. require some redundant typing which is saved by PLx Patterns (lazy evaluation). They are either plain wrapper classes or include variant implementations for the most common pattern types and deliver a more or less unified way for the described kind of placeholding.

Unification however can only be approximated as Patterns, even those of one type (e.g. ListPatterns), are defining different behaviour: not all inputs of a source pattern x can be dynamically updated (e.g. the start of a Pseries), not all of them are allowed to be Patterns itself. Implementation and usage may differ a bit from class to class. If there is no PLx implementation of a source Pattern class you can use PL as a general pattern placeholder input, see PL help file for an example. PLbindef and PLbindefPar allow key stream replacements in shortcut object prototyping syntax.

NOTE: PL follows a paradigm of immediate replacement. There are cases though where you might prefer to finish streams or substreams before replacement, especially when syncing comes into play, for these options consider PLn and the cutItems arg of PLx list patterns.

WARNING: Feeding a looped process with an invalid input has always the potential to lead to hangs. See PsymNilSafe and PLx and live coding with Strings for some remarks on that.

PLx pattern classes

value and event patterns

PL, PLn, PLseq, PLser, PLrand, PLwrand, PLshuf, PLshufn, PLslide, PLtuple, PLwalk, PLswitch, PLswitch1

value patterns

PLwhite, PLlprand, PLhprand, PLmeanrand, PLbrown, PLgbrown, PLseries, PLgeom, PLbeta, PLcauchy, PLgauss, PLpoisson, PLexprand

filter patterns

PLnaryop, PLnaryFunc, PLIdev

subclasses of Pdef

PLbindef, PLbindefPar

Examples

 

Ex. 1a: ListPatterns placeholder constructs with Plazy

Similar placeholder constructs with Pcollect and Pfunc have similar drawbacks concerning replacement. However, this type of "delayed replacement" might be wanted in some cases and is also possible with PLx patterns, see PLn and the cutItems arg of PLx list patterns.

 

Ex. 1b: PLx implementation of ListPatterns

PLx Patterns take symbols as input. Derived Streams get the values of the Environment of streamification.

 

Ex. 1c: PLx implementation of Non-ListPatterns

 

Ex. 1d: Plain PL

A general placeholder that can be updated after instantiation. Its repeats arg defaults to inf.

PL can also be used with Patterns which don't have a PLx implementation. See PL for an example.

 

Ex. 2: Playing in different Environments

 

Ex. 3: Use with VarGui

See VarGui and VarGui shortcut builds for further examples.

 

Ex. 4: The repeats arg

PLx Patterns' repeats arg defaults to inf. This makes sense in situations where you want to go on replacing items on the fly. If a PLx Patterns is itself enclosed you may want to set it to a different value. Anyway the resulting number of repeats is the product of outer and inner repeats.

 

Ex. 5a: Updating input of N-ary operators

One may want to have the choice to update inputs of N-ary operators applied to Patterns too. A common case is clipping. Say you have a Pcauchy pattern (distribution with a relatively high number of outliers) and want to dynamically change its mean value and clip bounds.

For replacing operators dynamically take PLnaryFunc with the operator wrapped into a Function.

 

Ex. 5b: Updating input of N-ary Functions

Self-defined functions can be used as with PLnaryop.

Ex. 6: PLbind / PLbindef