Monad/dyad definition

From J Wiki
Jump to navigation Jump to search


<=   =>

As discussed in the earlier section on ambivalence, all verbs had two definitions, a monad and a dyad. You have defined only a monad for centigrade. What about the dyad?

   23 centigrade 32
|domain error: centigrade
|   23     centigrade 32

Since you didn't provide a dyad definition, it is empty and this is treated as if the dyad had no arguments in its domain, and any arguments you give will cause a domain error.

Let's examine some simple examples of defining dyadic, monadic, and both cases.

   monadminus =. 3 : 0
- y
)
   monadminus 5
_5
   5 monadminus 3
|domain error: monadminus
|   5     monadminus 3

The above defines the monad of the verb named monadminus. Applying it monadically works and applying it dyadically fails.

In one-line definitions like this you can take a shortcut and make the definition on a single line and avoid entering the special input mode that needs to be ended with the ). The following is an equivalent way of doing the above definition:

   monadminus =. 3 : '- y'

The string contains the single line that makes up the definition. It is provided directly as the right argument of : instead of the 0 used earlier.

So far you have defined just the monadic case of a verb. You can also define a verb with just a dyadic definition. Instead of 3 as the left argument to : use a 4 to define the dyadic case.

   dyadminus =. 4 : 'x - y'
   5 dyadminus 3
2
   dyadminus 5
|domain error: dyadminus
|       dyadminus 5

In the monad case the y name is the right argument and in the dyad case x is the left argument and y is the right.

What if you want to define both cases of a verb?

   minus =. 3 : 0
- y
:
x - y
)

The : by itself on a line separates the monad and dyad definitions.

   3 minus 5
_2
   5 minus 3
2
   minus 5
_5


<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106