Variant

The Variant operator specifies the value of an option to be used by its left operand function.

Examples

      ('a' ⎕R 'x') 'ABC'           ⍝ 'a' replaced with 'x'
ABC

      ('a' ⎕R 'x' ⍠ 'IC' 1) 'ABC'  ⍝ .. Ignoring Case
xBC

      IgnCase ← ⍠ 'IC' 1
      
      'a' ⎕R 'x' IgnCase 'ABC'
xBC 

The following derived function returns the location of the word 'variant' within its right argument using default values for all the options.

      f1 ← 'variant' ⎕S 0
      f1 'The variant Variant operator'
4

It may be modified to perform a case-insensitive search:

      (f1 ⍠ 1) 'The variant Variant operator'
4 12

This modified function may be named:

      f2 ← f1 ⍠ 1
      f2 'The variant Variant operator'
4 12

The modified function may itself be modified, in this case to revert to a case sensitive search:

      f3 ← f2 ⍠ 0
      f3 'The variant Variant operator'
4

This is equivalent to:

      (f1 ⍠ 1 ⍠ 0) 'The variant Variant operator'
4

Language Elements