Vocabulary/ampm

From J Wiki
Jump to navigation Jump to search

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

m&v y u&n y Bond Conjunction

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


(m&v) makes a monad out of a dyad v by supplying the (noun) value m as the left argument of v

(m&v y) is the same as (m v y)

   triple =: 3&*
   i: 3
_3 _2 _1 0 1 2 3

   triple i: 3  NB. Same as 3 * i: 3
_9 _6 _3 0 3 6 9

Conversely...

(u&n) makes a monad out of a dyad u by supplying the (noun) value n as the right argument of u

(u&n y) is the same as (y u n)

   i:3
_3 _2 _1 0 1 2 3

   gt0=: >&0
   gt0 i:3  NB. Same as (i:3) > 0
0 0 0 0 1 1 1

Common Uses

1. Weld a noun to a verb, creating a unit that bypasses processing by other modifiers. To prefix 'Mr. ' to each boxed string:

   'Mr. '&, each 'Jones';'Smith';'Williams'
+---------+---------+------------+
|Mr. Jones|Mr. Smith|Mr. Williams|
+---------+---------+------------+

2. Create a monad out of a dyad when one is required.


x m&v y x u&n y Bond Conjunction

Rank 0 _ -- operates on atoms of x, and the entirety of y -- WHY IS THIS IMPORTANT?


Warning.png This form has been removed from J Version 9.6 and later

The dyad form applies the monad form to y repeatedly x times...

  • Phrase:  x m&v y applies m&v to y repeatedly x times, and is equivalent to:  x (m&v @ ] ^: [) y
  • Phrase:  x u&n y applies u&n to y repeatedly x times, and is equivalent to:  x (u&n @ ] ^: [) y

See above for a description of the monadic form.

Note that we bind to the value (which will be constant) rather than to the name. We might use ".&name if we wanted the value to be a name of a noun.