Scalar function: Difference between revisions

Jump to navigation Jump to search
726 bytes added ,  09:24, 31 March 2020
m (13 revisions imported: Migrate from miraheze)
Line 3: Line 3:
Only a particular [[valence]] of a function is labelled "scalar". The scalar monad [[Not]] usually shares the glyph <source lang=apl inline>~</source> with non-scalar dyad [[Without]], and similarly scalar [[Roll]] and non-scalar [[Deal]] are both written <source lang=apl inline>?</source>.
Only a particular [[valence]] of a function is labelled "scalar". The scalar monad [[Not]] usually shares the glyph <source lang=apl inline>~</source> with non-scalar dyad [[Without]], and similarly scalar [[Roll]] and non-scalar [[Deal]] are both written <source lang=apl inline>?</source>.


== User defined scalar functions ==
In dialects with the [[Over]] operator (<source lang=apl inline>⍥</source>), any function can be used as a scalar function (that is, be applied to all simple scalars) using the [[derived monadic operator]] <source lang=apl inline>perv←⍥0</source>. In dialects that support [[dfn]]s, this operator can be defined<ref>[[John Scholes]], [https://dfns.dyalog.com/n_perv.htm perv] (Scalar pervasion). dfns workspace, 2019-02-17.</ref> as:
<source lang=apl>
perv←{⍺←⊢              ⍝ Scalar pervasion
    1=≡⍺ ⍵ ⍵:⍺ ⍺⍺ ⍵    ⍝ (⍺ and) ⍵ depth 0: operand fn application
            ⍺ ∇¨⍵      ⍝ (⍺ or) ⍵ deeper: recursive traversal.
}
</source>
== Standard scalar functions ==
== Standard scalar functions ==


Navigation menu