Pervasion
Pervasion during function application is the concept of a function being defined in terms of the simple scalars in nested arrays. It is a feature of nested array languages, while flat array languages usually do have function pervade into boxes. Pervasion can be seen recursing into all nested elements.
Scalar functions exhibit pervasion by default, whereas mixed functions and user defined functions do not. However, in dialects with the Depth operator (⍥
), a function can be used as a scalar function (that is, be applied to all simple scalars) using the ⍥0
:
NonScalarFn←{⍵:'t' ⋄ 'f'} (NonScalarFn⍥0) (0 1) 1 (⊂1 0) ┌──┬─┬────┐ │ft│t│┌──┐│ │ │ ││tf││ │ │ │└──┘│ └──┴─┴────┘
In dzaima/APL the dyadic form of Depth is not yet implemented, so this definition will only work for monadic function application
In dialects that support dfns, this operator can be defined[1] as:
perv←{⍺←⊢ ⍝ Scalar pervasion 1=≡⍺ ⍵ ⍵:⍺ ⍺⍺ ⍵ ⍝ (⍺ and) ⍵ depth 0: operand fn application ⍺ ∇¨⍵ ⍝ (⍺ or) ⍵ deeper: recursive traversal. }
In all dialects that support user defined tradops, the operator for monadic function application can be defined as:
R←(f perv)Y →(0=≡Y)/APPLY R←f perv¨Y →0 APPLY:R←f Y
APL features [edit] | |
---|---|
Built-ins | Primitives (functions, operators) ∙ Quad name |
Array model | Shape ∙ Rank ∙ Depth ∙ Bound ∙ Index (Indexing) ∙ Axis ∙ Ravel ∙ Ravel order ∙ Element ∙ Scalar ∙ Vector ∙ Matrix ∙ Simple scalar ∙ Simple array ∙ Nested array ∙ Cell ∙ Major cell ∙ Subarray ∙ Empty array ∙ Prototype |
Data types | Number (Boolean, Complex number) ∙ Character (String) ∙ Box ∙ Namespace ∙ Function array |
Concepts and paradigms | Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity element ∙ Complex floor ∙ Array ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ Glyph ∙ Leading axis theory ∙ Major cell search ∙ First-class function |
Errors | LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR ∙ DOMAIN ERROR ∙ LENGTH ERROR ∙ INDEX ERROR ∙ VALUE ERROR ∙ EVOLUTION ERROR |
- ↑ John Scholes, perv (Scalar pervasion). dfns workspace, 2019-02-17.