Vocabulary/squarelfco

From J Wiki
Jump to: navigation, search

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

[: Cap

Rank Infinity -- operates on [x and] y as a whole -- WHY IS THIS IMPORTANT?



1. Raises domain error whenever executed as monad or dyad, whatever the argument(s).

2. In a tacit phrase ([: f g): caps the left branch of a fork.

This is a syntactic trick to employ a fork to implement: f(g(x)) -- the composition of the two functions: f and g.

The primitive: [: is not actually executed.

   13 : 'f(g(y))'
[: f g

Common uses

1. To force an error when a tacitly defined verb only meant to be used monadically is accidentally employed dyadically, and vice-versa

Note the use of Monad-Dyad (:) to provide separate tacit definitions for monadic and dyadic uses of the verb.

   star=: *         NB. Any verb can be executed as monad or dyad
   star _99 99 0
_1 1 0
   3 star 5
15

   signum=: * : [:  NB. This verb will fail if executed dyadically
   signum _99 99 0
_1 1 0
   3 signum 5
|domain error: signum
|   3     signum 5

   times=: [: : *   NB. This verb will fail if executed monadically
   3 times 5
15
   times _99 99 0
|domain error: times
|       times _99 99 0

2. To implement f(g(y) as above.


Related primitives

Compose (&), Appose (&), At (@:), Atop (@), Hook ((u v)), Fork ((f g h))


More Information

1. Except for its appearance in code, ([: g h) is exactly equivalent to g@:h .


Use These Combinations

Combinations using [: y that have exceptionally good performance include those shown in Searching and Matching Items: Fast List Operations (FLOs), as well as the following:

What it does Type;

Precisions;
Ranks

Syntax Variants;

Restrictions

Benefits;

Bug Warnings

Applying f/ after g

(f and g are any atomic verbs)

x f/@:g y

x ([: f/ g) y

avoids recopying arguments
Extract multiple substrings into a list Boolean list, byte list x ;@:(<;.0) y or [: ; <;.0 avoids boxing, avoids creating subarrays
Razed selections x (;@{) y also x ([: ; {) y
Concatenated results on intervals ;@:(<@u;.n) y

x ;@:(<@u;.n) y

n e. _2 _1 1 2; also [: ; (<@u;.n); also <@:u Bug Warning: This is computed as <@:u even if <@u is coded
Concatenated running totals on intervals (running total, but total is reset at start of each interval) ;@:(<@(f/\);.n) y

x ;@:(<@(f/\);.n) y
(f is any verb)

n e. _2 _1 1 2; also [: ; (f... also <@:(f/\); also <@:
Arrays of random numbers x ?@$ y

x([: ? $)y

?. in place of ?

@: in place of @
# in place of $

does not create x $ y