Pspawn is a pattern-based version of Pspawner. Where Pspawner uses a Routine-style function to determine when and how to spawn child patterns into the result stream, Pspawn uses an event pattern to determine the actions to take.
Recommended to read the Pspawner help file to become familiar with pattern spawning capabilities.
Of these, only the child events are returned to the event stream player during play. The parent events are used strictly internally to control spawning behavior. The parent and child event streams do not mix together. Thus pattern composition ( Pchain ) and parallelization ( Ppar ) may be used without special handling. It is up to the user to be aware of whether the parent or child stream should be subject to further manipulation, and put that manipulation in the right place. If it is to affect the child stream, it should enclose the entire Pspawn; for the parent stream, it should be inside Pspawn. (See the examples below.)
Pspawn uses the following items in the parent pattern:
'pattern' in the event | Resulting behavior |
A Function : { ... } | The function should return a pattern; this pattern is spawned. |
A Ref to a pattern: `Pbind(...) | The referenced pattern is spawned. |
A Symbol : \scaleUp | The pattern is looked up in the event's 'dict'. |
Normally, when a pattern appears inside another pattern, the subpattern is embedded in the main output stream. It is not visible to the outside world as a pattern in itself; only its values appear.
When using Pspawn, a sub pattern must be returned directly into the event. To accomplish this, every such pattern should be wrapped in a Ref :
Hint: Pfunc is another good way to wrap patterns, because it simply returns its result values without further embedding. See the first example.
pattern |
An event pattern (typically Pbind) encapsulating the desired spawning behavior. Parameters in this event are described below. |
spawnProtoEvent |
The event prototype against which the pattern is evaluated. Good for giving default values that should apply to all spawning (parent) events. |