Chapter 13: Operators Tacitly Defined

13.1 Introduction

J provides built-in operators such as the composition-conjunction @. In the previous chapter we looked at defining our own operators explicitly. In this chapter we look at defining operators tacitly.

13.1.1 Preparations

It will be helpful to have a few verbs for making examples. Verbs f, g and h are meant to be trivial functions where, by looking at their results, it is easy to track how they were applied.

      f =: 'f' & ,
      g =: 'g' & ,
      h =: 'h' & ,

f 'a' g 'a' f g 'a'

13.2 A Tacit Adverb

Recall from Chapter 07 the Rank conjunction, ("). For example, the verb (< " 0) applies Box (<) to each rank-0 (scalar) item of the argument.

A tacit adverb to apply a given verb to each scalar can be written as (" 0)

each =: " 0 < each < each 'abc'

The scheme is, that for a conjunction C and a noun N, the expression (C N) denotes an adverb such that:

         x (C N)  means  x C N 

Here is another example. Recall from Chapter 10 the Power conjunction (^:) which applies a verb repeatedly, so that ( f ^: 3 y) means f f f y. An adverb which applies a verb twice can be written as ^: 2

twice =: ^: 2 f twice (f twice) 'a'

13.3 Patterns

The tacit adverb (" 0) is patterned as a conjunction followed by a noun. If we write V for a verb, N for a noun, A for an adverb and C for a conjunction, then this pattern, conjunction-followed-by-noun, can be called pattern CN.

The J language attaches meaning to many different patterns. For example, the meaning of an expression of pattern VN is: the application of a verb to a noun argument. The meaning of pattern VVV is a fork of three verbs.

In this chapter we will look at further patterns useful for defining operators. We have met our first example using pattern CN above to define an adverb. The patterns fall into groups, so we look at each group in turn. Patterns of two objects are called bidents and patterns of three are called tridents.

13.4 Adverbs From Bonded Conjunctions

We have already met the bident CN. Recall its scheme, which is: if C is a conjunction, N a noun, then the bident (C N) denotes an adverb such that for an argument x

    x (C N) means  x C N 

Altogether there are four similar schemes

pattern is with scheme
CN adverb x (C N) means x C N
NC adverb x (N C) means N C x
VC adverb x (V C) means V C x
CV adverb x (C V) means x C V

Here is another example, a bident of pattern VC.

   A =: h @   NB. verb conjunction

A g A (g A) 'a'

These patterns are a form of bonding (or currying) whereby we take a two-argument function and fix the value of one of its arguments to get a one-argument function

However, there is a difference between bonding a dyadic verb (as in + & 2 for example) and bonding a conjunction. With the conjunction, there is no need for a bonding operator such as &. We just write (" 0) with no intervening operator. The reason is that in the case of + & 2, omitting the & would give + 2 which means: apply the monadic case of + to 2, giving 2. However, conjunctions don't have monadic cases, so the bident (" 0) is recognised as a bonding.

13.5 Compositions of Adverbs

If A0 and A1 are adverbs, then the bident (A0 A1) denotes an adverb which applies A0 and then A1

For example:

   A0 =: f @    NB. adverb (bident VC)
   A1 =: @ g    NB. adverb (bident CV)

h A0 (h A0) A1 Z =: A0 A1 h Z h Z 'a'
A0 A1

and similarly for a trident of 3 adverbs, A0 A1 and A2. Thus we have the two schemes:

pattern is with scheme
AA adverb x (A0 A1) means (x A0) A1
AAA adverb x (A0 A1 A2) means ((x A0) A1) A2

13.6 Hook-Making Adverb

If A is an adverb, V a verb, then the bident (A V) denotes an adverb. This adverb, given an argument x generates a verb in the form of the hook (x A) V. For example:

av =: ~ f , av , av 'a'
~ f
,~ f

The scheme is:
pattern is with scheme
AV adverb x (A V) means (x A) V

13.7 Fork-Making Adverb

If A is an adverb, V1 and V2 are verbs, then the trident (A V1 V2) denotes an adverb which generates a fork. For example:

   avv =: / % #  NB. adv verb verb

avv + avv + avv 2 4
/ % #
+/ % #

The scheme for trident AVV is:
pattern is with scheme
AVV adverb x (A V1 V2) means (x A) V1 V2

13.8 Identity Operators

It will be useful at this point to introduce identity-operators for the sake of the examples which follow. The built-in adverb ]: is the identity-adverb. Its argument can be a noun or verb. Its result is identical to its argument.

+ ]: (f@g) ]: 6 ]:

The built-in conjunction [., called "Lev", is the left-identity conjunction. Its arguments can be nouns or verbs. Its result is identical to its left argument. Similarly, for the conjunction ]., called "Dex", its result is identical to its right argument.

f [. g f ]. g

Now we return to our theme of patterns defining operators.

13.9 Fork-making Conjunctions

Now we look at patterns denoting conjunctions which generate forks.

Suppose that C0,C1, ... are conjunctions, V0,V1, ... are verbs, and A0 ,A1 ... are adverbs.

Then the trident (C0 V1 C2) for example, denotes a conjunction according to the scheme for the pattern CVC below. We have schemes for these patterns:

pattern is with scheme
CVC conjunction x (C0 V1 C2) y means (x C0 y) V1 (x C2 y)
VVC conjunction x (V0 V1 C2) y means V0 V1 (x C2 y)
CVV conjunction x (C0 V1 V2) y means (x C0 y) V1 V2
AAV conjunction x (A0 A1 V2) y means (x A0) (y A1) V2

For example,

cvc =: [. , ]. foo =: f cvc g foo 'a'
[. , ].
f , g

Here is a derivation of the last result:

   foo 'a'
   (f cvc g) 'a'              NB. by defn of foo
   (f ([. , ].) g) 'a'        NB. by defn of cvc
   ((f [. g) , (f ]. g)) 'a'  NB. by trident CVC
   (f , g) 'a'                NB. by defn of [. and ].   
   (f 'a') , (g 'a')          NB. f , g is a fork
   ('fa' , 'ga')              NB. by defn of f and g

13.10 More Patterns

There are schemes for further patterns, as shown in the following table.

pattern is with scheme
NCA adverb x (N0 C1 A2) means N0 C1 (x A2)
VCA adverb x (V0 C1 A2) y means V0 C1 (x A2)
ACN adverb x (A0 C1 N2) means (x A0) C1 N2
ACV adverb x (A0 C1 V2) means (x A1) C1 V2
ACA adverb x (A0 C1 A2) means (x A0) C1 (y A2)
AC adverb x (A0 C1) means (x A0) C1 x
CA conjunction x (C0 A1) y means (x C0 y) A1
CAA conjunction x (C0 A1 A2) y means ((x C0 y) A1) A2
NCC conjunction x (N0 C1 C2) y means N0 C1 (x C2 y)
VCC conjunction x (V0 C1 C2) y means V0 C1 (x C2 y)
ACC conjunction x (A0 C1 C2) y means (x A0) C1 (x C2 y)
CCN conjunction x (C0 C1 N2) y means (x C0 y) C1 N2
CCA conjunction x (C0 C1 A2) y means (x C0 y) C1 (y A2)
CCC conjunction x (C0 C1 C2) y means (x C0 y) C1 (x C2 y)

This is the end of Chapter 13.

Table of Contents

Copyright © Roger Stokes 2002. This material may be freely reproduced, provided that this copyright notice is also reproduced.

last updated 16 Mar 2002