Behind {R}←{X}f⍛gY

Information

The glyph is not available in Classic Edition, and the behind operator is instead represented by ⎕U235B.

f can be any monadic function that returns a result; the result must be suitable as the left argument to the function g.

g can be any dyadic function; it does not need to return a result.

Y can be any array that is suitable as the right argument to the function g. If X is omitted, Y must also be suitable as the right argument to the function f.

X can be any array that is suitable as the right argument to the function f.

The derived function is equivalent to either (f Y) g Y or (f X) g Y, depending on whether X is specified or not.

The behind operator allows functions to be glued together to build up more complex functions. For further information, see Function Composition.

Examples: Monadic Application of Derived Function

Are numbers in a sequence identical to the first number in that sequence?

      = 2 7 1 8 2 8 1 8 2 8
1 0 0 0 1 0 0 0 1 0 

Are the characters within each vector unique?

      ¨ 'Hello' 'Helo'
0 1

Where in a Boolean mask does it match its reverse?

       0 1 1 1 1 0 0 0 0
0 0 0 0 1 0 0 0 0

Prefix a vector with its final element:

      /⍛,'XYZ'
ZXYZ

Identify where the odd numbers are located within a vector, and add 1 to them:

      2| 3 1 4 1 5 9     ⍝ create mask of odd numbers
1 1 0 1 1 1
      2|+ 3 1 4 1 5 9   ⍝ add one to the odd numbers
4 2 4 2 6 10

Identify the numbers in a vector greater than 3, and filter to return only those numbers:

      3< 2 7 1 8 2 8     ⍝ create mask
0 1 0 1 0 1
      3<⍛/ 2 7 1 8 2 8   ⍝ apply filter
7 8 8

Identify the integers in a vector of numbers, and filter to return only the integers:

      = 1 3.2 ¯5 0 ¯3.2 8.1     ⍝ create mask
1 0 1 1 0 0
      =⍛/ 1 3.2 ¯5 0 ¯3.2 8.1   ⍝ apply filter
1 ¯5 0

Identify the palindromes, and filter to return only the palindromes:

      ¨ 'racecar' 'racer' 'hanna' 'asa'   ⍝ create mask
1 0 0 1
      ¨⍛/ 'racecar' 'racer' 'hanna' 'asa' ⍝ apply filter
racecar asa

Find the mean value of a vector of numbers, identify the individual numbers in the vector that are greater than the mean value, and filter to retun only those numbers:

      (+÷≢) 3 1 4 1 5 9 2 6       ⍝ calculate mean value
3.875
      (+÷≢)< 3 1 4 1 5 9 2 6     ⍝ create mask
0 0 1 0 1 1 0 1
      (+÷≢)<⍛/ 3 1 4 1 5 9 2 6   ⍝ apply filter
4 5 9 6

Examples: Dyadic Application of Derived Function

Some functions require their left arguments to be enclosed to achieve the desired result. Without behind, the left argument needs to be parenthesised to enclose the left argument. With behind, a new function can be derived that achieves the required enclosure by including ⊂⍛ before the main function. For example:

Does the left argument exist within the right argument?

      ('dog')  'cat' 'dog' 'bird'    ⍝ without behind
1
      'dog'  'cat' 'dog' 'bird'     ⍝ with behind
1

Select elements using the index function:

      1 4 1 13  ⎕A
ADAM

Write a vector of vectors to a file:

      'abc' 'def' ⎕NPUT 'myfile.txt'

You can compose functions to achieve useful functionality. For example:

Evaluate x²+2 for multiple values of x:

      (5 10) 1 0 2              ⍝ without behind
      5 10  1 0 2              ⍝ with behind
27 102

Convert numbers to text as they are catenated:

      'there are ',2,' things'
there are 2 things

Reshape an array to conform to the shape of another array:

      'abc'  'z'
zzz

Some functionality does not exist as a primitive but can easily be composed using behind. For example:

Identify the first occurrence of an element starting from the end of the source:

      'abracadabra'  'ab'
1 3

Construct a Boolean mask from a length and the indices of the 1s (inverse of monadic ):

      10  1 3 5
1 0 1 0 1 0 0 0 0 0

Filter to return elements that correspond to 0 in a Boolean mask – the opposite of reduce (/), which returns elements that correspond to 1 in a Boolean mask.:

      0 1 0 1 1 0 ~⍛/ 'Dyalog'
Dag

Take elements from both ends of the source:

      3 (↑⍪-) ⎕A
ABCXYZ

Sort a vector by values in another vector:

      30 40 20  'Abe' 'Bea' 'Carl'
Carl Abe Bea

Split a vector with a function that can be applied either monadically (in which case it uses the initial character as separator) or dyadically (in which case it uses the left argument as separator):

      ]Boxing on
      Split≠⊆⊢
      Text',I S,EAT ING,RATES'
      Split Text     ⍝ Split at occurences of first element
┌───┬───────┬─────┐
I SEAT INGRATES
└───┴───────┴─────┘
      ' 'SPLIT TEXT  ⍝ Split at occurences of left argument
┌──┬─────┬─────────┐
,IS,EATING,RATES
└──┴─────┴─────────┘