Vocabulary/scapco

From J Wiki
Jump to: navigation, search

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

[x] u S: n y Spread Conjunction

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



(u S:0 y) applies verb u to each leaf of y, creating an array whose items are the results of the leaves, with framing fill added as needed.

Contrast this with Level At (u L:0 y), which returns a result in which each leaf of y has been replaced by the result of executing u on it.

A leaf of y is a noun inside y that itself has no boxed contents.

A leaf is either empty or unboxed.

   ] y=: (<0 1),(<<2 3),(<<<4 5)
+---+-----+-------+
|0 1|+---+|+-----+|
|   ||2 3|||+---+||
|   |+---+|||4 5|||
|   |     ||+---+||
|   |     |+-----+|
+---+-----+-------+
   NB. y is sample noun of nested boxed items
   NB. --The leaves are (0 1), (2 3) and (4 5)

   u=: |.   NB. sample verb (Reverse) to apply to leaves

   u S:0 y
1 0
3 2
5 4

Compare this with the action of Level At (L:)

([x] u S:n y) applies u to the leaves of y in the same way as ([x] u L:n y) but it collects the results as the items of an array.

See Level At (L:) for details, including

  • values of n other than 0
  • negative values of n
  • the dyadic case (x S: n y)

Common Uses

Apply verb u to the leaves (innermost opened items) of a boxed noun y

   ] y=: 'alpha' ; 'bravo' ;'charlie'
+-----+-----+-------+
|alpha|bravo|charlie|
+-----+-----+-------+

   toupper S:0 y
ALPHA
BRAVO
CHARLIE

Related Primitives

Level Of (L. y), Level At (u L: n)