Vocabulary/cou

From J Wiki
Jump to navigation Jump to search

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

u : v Monad-Dyad Conjunction

Rank -- depends on the ranks of u and v -- WHY IS THIS IMPORTANT?


Derives a dual-valence verb, which executes

The ranks of the derived verb (u : v) are as you'd expect:

  • the monadic rank is the monadic rank of u
  • the dyadic rank is the dyadic rank of v.

To create an adverb or conjunction which derives a dual-valence verb when passed its operands, see below.

Information.png Conjunction Def (:) has several different uses, requiring several pages to document it


Common uses

1. Define a single name with different monadic and dyadic forms

sort =: /:~ : /:  NB. monadic, sort y; dyadic, sort x in the order given by y

2. Provide a default value for argument x to let you call a given dyad monadically (i.e. with just a y-argument)

NB. Return the date x days in the future (default 0)
getdate =: (0&getdate) : (dyad define)
NB. body of dyadic verb here
)

3. Create a verb that can't be called with the wrong valence

Executes Cap ([:) in place of the bad valence to force  domain error

   mp =: +/ . *          NB. define a name for matrix product
   mtx =: i. 2 2         NB. a matrix
   mp mtx                NB. Oops, we called mp monadically, yielding an unexplainable result
2
   mp =: [: : (+/ . *)   NB. This'll fix it
   mp mtx
|domain error: mp
|       mp mtx

More Information

Creation of a modifier which derives a dual-valence verb is most directly accomplished by using ':' within an explicit definition (this is a special syntax, and, although similar in function, is different from the Monad/Dyad conjunction :):

rank=: 2 : 0   
u"(v y) y
:
u"(x v y) y
)
   1 <@] rank [ i.3 3  
┌─────┬─────┬─────┐
│0 1 2│3 4 5│6 7 8│
└─────┴─────┴─────┘

To instead create an ambivalent modifier using Monad/Dyad, simply pass the operand verb(s) u [and v] to the given modifier to create the verb of the desired valence, and use Monad-Dyad between the two verbs.

   rank=: {{ u{{u"(v y) y}}v : (u{{x u"(x v y) y}}v) }}  
   rank   NB. dual-valence conjunction
2 : 'u{{ u"(v y) y }}v  : (u{{ x u"(x v y) y }} v) '

Notice that (u{{u"(v y) y}}v) derives a verb, which serves as the u operand to Monad-Dyad above. Use of Monad-Dyad within an explicit modifier definition is needed when creating a dual-valence modifier whose definition involves passing an expression given in terms of x and/or y (in the above example, both (v y) and (x v y) are such expressions) as an operand to a modifier (here, the rank (") conjunction).