From J Wiki
Jump to: navigation, search

>> <<   Back to: Vocabulary Thru to: Dictionary

u !. n Fit (Customize) Conjunction

The customized verb u!.n is a predetermined variant of primitive verb u according to the (noun) operand n.

Only when u is one of these primitives can it be customized with !.

monadic * Adjust the Absolute Tolerance to (n)
monadic <. >. ~. = ~: #: e. x: Adjust the Relative Tolerance to (n)
dyadic < <: > >: +. *. -. -: | E. i. i: = ~: #: e. u/. Adjust the Tolerance to (n)
dyadic ^ p. Stope Function
monadic ; Change the Fill Atom to (n)
dyadic $ |. , ,. ,: # {. Change the Fill Atom to (n)
monadic ": Set the Print Precision for floating-point values to (n)

Common Uses

1. Alter the comparison tolerance of a number primitive, e.g. Equal (=).

In J terms this means: make a new customized verb (=!.n) which treats two numbers as equal if their difference is  n*z or less, where z is the greater of the magnitudes (absolute values) of x and y.

except for * y, where a number is treated as equal to 0 if its magnitude is less than n

   ] n=: 2^_34       NB. choose a value for the tolerance
   2 = 2+n           NB. Default tolerance is much smaller: 2^_44
   2 (=!.n) 2+n      NB. But (=!.n) treats 2 and (2+n) as equal
   2 (=!.n) 2+n+n    NB. Still equal! (See below)
   2 (=!.n) 2+n+n+n

Note: J will not accept values of n greater than  2^_34 . To learn why not, see Essays/Tolerant Comparison. This essay also explains why 2 and 2+n+n are tolerated as effectively equal above.

2. Change the fill atom used for filling empty places during [x] {. y and x |. y

   _5 {. 'abc'
   _5 {.!.'*' 'abc'

3. Change the fill atom used for filling empty places when an array is extended by x , y, x ,. y, x ,: y, or ; y to match the shape of the result

   'ab' ,: 'abc'
   'ab' ,:!.'*' 'abc'

Note that these verbs always replicate atoms rather than using fill:

   'a' ,: 'abc'
   'a' ,:!.'*' 'abc'

4. When a verb operates on an arguments whose rank is higher than the verb's, the verb is executed on each cell separately, and the results are assembled into a single array. During assembly, the results are brought to a common shape by adding fill as required. There is no way to alter the atom used for this fill. It is always either 0, ' ', a:, or s: '' depending on the type of the value being filled.

More Information

1. These primitives:  +. *. | #: have an implied tolerant comparison, such as Residue  x | y which tolerantly decides whether the quotient  y % x is an integer or not.


If a tolerance is specified using u/.!.f, that tolerance is used as the default tolerance during the execution of u.