From J Wiki
Jump to navigation Jump to search

Back to: Vocabulary

Gerunds and Atomic Representation


A gerund is a noun that represents one or more verbs.

You use a gerund when you want to

  • Provide a verb as an argument to another verb
    because only nouns can be arguments to verbs
  • Provide more than two verb operands to an adverb, or more than three verb operands to a conjunction

You create a gerund with the Tie conjunction (`).


One of the variants of the Amend adverb (}) uses three verb operands, which are passed in as a single gerund:

   ]a =. 'abracadabra'
   'x' [`([: I. 'a' = ])`]} a 
   ('x' [ a) ('x' ([: I. 'a' = ]) a)} ('x' ] a)   NB. Execution of the gerund form is equivalent to this


1. A gerund is a list of boxes or a single atomic box. Each box in a gerund describes one verb.

2. Because of its clever definition, (u`v) can be used to create gerunds containing any number of verbs. Each of u/v that is a verb is converted to a single-box gerund form, while each that is a noun is left unchanged. Then the possibly-modified operands are joined into a single list. Thus, when a sequence such as


is executed, the first execution is


producing a 2-atom list of boxes, followed by

   ((,'+');,'-') ` *

which leaves unchanged the left argument (the previously-created gerund, which is a noun) and appends the gerund form of the right argument.

3. To create the gerund form of a single verb, use u`'' or ''`v which will produce a single gerund as a one-atom list.

Exactly What Is A Gerund?

  • A gerund is not a special datatype.
  • A gerund is a single box or list of boxes each of which is the atomic representation of a verb.
  • You can create a gerund by giving a verb operand to the Tie conjunction (`)
  • But you can also create a gerund by hand, building up the atomic representation.

So what is a gerund?

A gerund is a box or list of boxes, where each box contains the atomic representation of a verb.

Atomic Representation

A gerund is a special case of atomic representation (AR), which is a way of representing any entity as an atomic boxed noun.

You can create an atomic representation by following the rules below, or you can use 5!:1 to produce the AR of a named entity.

   sum =: +/
|| ||+|||
|| |+-+||

In addition, you can use the Tie conjunction (`) to create the AR of a verb.

AR format

An AR is an atomic box whose contents are

  • a list of character(s) representing either
    if there is only a single character, the contents will be list whose single item is this character
    • a primitive
    • a name
  • a list of 2 boxes, where
    • the first box contains characters, either
      • a primitive
      • a code indicating how the remaining box is to be interpreted
    • the contents of the second box is interpreted according to the value of the first box, and is either the value of a noun, or a list of ARs

To see the AR of a named entity, execute 5!:1<'entityname'.

How to map trains and compound entities into AR format

To build an AR by hand, write out the sequence of J words that would represent the entity, and then emulate the action of the parser. Whenever the parser would execute a fragment, combine the words of the fragment into a single AR. What you are left with at the end of execution will be the final AR.
The table columns "Parse Row" and "Action" refer to J's parsing table.

Action Example Code to produce AR AR for example
- noun (when an AR is needed, for the final result or for an operand to an adverb or conjunction) 'abc' < (<,'0') , < value of noun < (<,'0') , < 'abc'
- named verb, adverb, or conjunction each If the entity itself is executed, the AR is the AR of its value. If not (i. e. only its name is needed), and the entity was assigned with the name of another entity, the AR is the boxed name of the other entity.

Example: in u@v, @ is executed, but u and v are not.

0 monad i. 5 None. These lines are executed to produce noun results which are passed into subsequent executions
1 monad *: i. 5
2 dyad 2 + 3
7 assignment name =. None. Ignored.
8 () (i. 5) None. Parsing continues inside the parentheses
3 adverb execution +/ < AR for value of adverb , < , AR for verb/noun < (<,'/') , < , < , '+'
4 conjunction execution ^.@| < AR for value of conjunction , < AR for left operand , AR for right operand < (<,'@') , < (< '^.') , (< , '|')
5 fork ({. - {:) < (<,'3') , < AR for left tine , AR for middle tine , AR for right tine < (<,'3') , < (< '{.') , (< , '-') , (< '{:')
7 hook (% {.) < (<,'2') , < AR for left tine , AR for right tine < (<,'2') , < (< , '%') , (< '{.')
6 modifier bident or trident (]: @:) < (<,'4') , < AR for first tine , AR for second tine [, AR for third tine] < (<,'4'),<(<']:'),(<'@:')