Help / Learning / Ap 1: Evaluating Expressions
>> << Pri JfC LJ Phr Dic Voc !: Rel NuVoc wd Help Learning J
|
Appendix 1: Evaluating ExpressionsA1.1 Introduction
Here we look at the process of evaluating a J expression. Evaluating a complete expression proceeds by a sequence of basic steps, such as obtaining the value assigned to a name, or applying a function to its argument(s). For example, given x =: 3 then the expression 4+5*x 19 is (in outline) evaluated by the steps:
The sequence in which the steps take place is governed by the grammatical (or "parsing") rules of the J language. The parsing rules have various consequences, or effects, which can be stated informally, for example:
These effects describe how an expression is implicitly parenthesized. Of course, we can always produce desired effects by writing explicit parentheses, even though they may not be needed. Further effects are:
and we will look at how the parsing rules give rise to these effects. To illustrate the process, we can use a function which models, or simulates, the evaluation process step by step, showing it at work in slow motion. This function, an adverb called EVM,is based on the description of the parsing algorithm given in the J Dictionary, section IIE. It is defined in a File:Help-learning-91a.ijs.txt. A1.2 First ExampleEvaluation of an expression such as 2+3 can be modelled by offering the argument '2+3' (a string, notice) to the modelling adverb EVM.
We see that '2+3' EVM computes the same value as 2+3, but EVM also produces a step-by-step record, or history, of the evaluation process. This history is displayed by entering the expression hist hist '' Queue Stack Rule +----------+ +------+---+---+---+ +----+ |mark 2 + 3| | | | | | | | +----------+ +------+---+---+---+ +----+ |mark 2 + | | 3 | | | | | | +----------+ +------+---+---+---+ +----+ |mark 2 | | + | 3 | | | | | +----------+ +------+---+---+---+ +----+ |mark | | 2 | + | 3 | | | | +----------+ +------+---+---+---+ +----+ | | | mark | 2 | + | 3 | |dyad| +----------+ +------+---+---+---+ +----+ | | | mark | 5 | | | | | +----------+ +------+---+---+---+ +----+ We see successive stages of the process. In this example there are six stages. Each stage is defined by the values of two variables. Firstly there is a "queue", initially containing the expression being evaluated, divided into words and preceded by a symbol to mark the beginning. Secondly, there is a "stack", initially empty. The first stage shows queue and stack at the outset. At each stage the stack is inspected to see if anything can be done, that is, whether the first few words in the stack form a pattern to which a rule applies. There are 9 of these rules, and each one is tried in turn. If no rule applies, then a word is transferred from the tail of the queue to the head of the stack, and we go to the next stage and try again. This process takes us from the first stage to the fifth stage. At the fifth stage, we find that a rule is applicable. This rule is identified as dyad in the rightmost column. Informally, the dyad rule is: if the first four items in the stack are something, noun, verb, noun, then apply verb to noun and noun to get new-noun, and replace the first four items in the stack by two, namely original-something followed by new-noun. The sixth and last stage shows the results of applying the "dyad" rule recognized at the previous stage. The rules are tried again, with no result, and there are no more words in the queue, so we have finished. The final result is the second item of the stack. The history is maintained in 3 global variables, Qh Sh and Rh. The expression hist computes a formatted display from these variables. A1.3 Parsing RulesIn this section an example is shown of each of the 9 parsing rules. Each rule looks for a pattern of items at the front of the stack, such as something verb noun verb. Each item of the stack is classified as one of the following: verb, noun, adverb, conjunction, name, left-parenthesis, right-parenthesis, assignment-symbol (=. or =:) or beginning-mark. To aid in a compact statement of the rules, larger classes of items can be formed. For example, an item is classified as an "EDGE" if it is a beginning-mark, an assignment-symbol or a left-parenthesis. The rules are always tried in the same order, the order in which they are presented below, beginning with the 'monad rule' and ending with the 'parenthesis rule'.
A1.3.1 Monad RuleIf the first 3 items of the stack are an "EDGE" followed by a verb followed by a noun, then the verb is applied (monadically) to the noun to give a result-value symbolized by Z say, and the value Z replaces the verb and noun in the stack. The scheme for transforming the items of the stack is: monad rule: EDGE VERB NOUN etc => EDGE Z etc where Z is the result computed by applying VERB to NOUN. For example:
hist '' Queue Stack Rule +---------+ +------+----+---+ +-----+ |mark *: 4| | | | | | | +---------+ +------+----+---+ +-----+ |mark *: | | 4 | | | | | +---------+ +------+----+---+ +-----+ |mark | | *: | 4 | | | | +---------+ +------+----+---+ +-----+ | | | mark | *: | 4 | |monad| +---------+ +------+----+---+ +-----+ | | | mark | 16 | | | | +---------+ +------+----+---+ +-----+ A1.3.2 Second Monad RuleAn item in the stack is classified as "EAVN" if it is an EDGE or an adverb or verb or noun. The scheme is: monad2 rule: EAVN VERB1 VERB2 NOUN etc => EAVN VERB1 Z etc where Z is VERB2 monadically applied to NOUN. For example:
hist '' Queue Stack Rule +-----------+ +------+-----+----+---+ +------+ |mark - *: 4| | | | | | | | +-----------+ +------+-----+----+---+ +------+ |mark - *: | | 4 | | | | | | +-----------+ +------+-----+----+---+ +------+ |mark - | | *: | 4 | | | | | +-----------+ +------+-----+----+---+ +------+ |mark | | - | *: | 4 | | | | +-----------+ +------+-----+----+---+ +------+ | | | mark | - | *: | 4 | |monad2| +-----------+ +------+-----+----+---+ +------+ | | | mark | - | 16 | | |monad | +-----------+ +------+-----+----+---+ +------+ | | | mark | _16 | | | | | +-----------+ +------+-----+----+---+ +------+ A1.3.3 Dyad RuleThe scheme is dyad rule: EAVN NOUN1 VERB NOUN2 etc => EAVN Z etc where Z is VERB applied dyadically to NOUN1 and NOUN2. For example.
hist '' Queue Stack Rule +----------+ +------+----+---+---+ +----+ |mark 3 * 4| | | | | | | | +----------+ +------+----+---+---+ +----+ |mark 3 * | | 4 | | | | | | +----------+ +------+----+---+---+ +----+ |mark 3 | | * | 4 | | | | | +----------+ +------+----+---+---+ +----+ |mark | | 3 | * | 4 | | | | +----------+ +------+----+---+---+ +----+ | | | mark | 3 | * | 4 | |dyad| +----------+ +------+----+---+---+ +----+ | | | mark | 12 | | | | | +----------+ +------+----+---+---+ +----+ A1.3.4 Adverb RuleAn item which is a verb or a noun is classified as a "VN" The scheme is: adverb rule: EAVN VN ADVERB etc => EAVN Z etc where Z is the result of applying ADVERB to VN. For example:
hist '' Queue Stack Rule +--------------+ +-------+-------+-------+-------+ +-----+ |mark + / 1 2 3| | | | | | | | +--------------+ +-------+-------+-------+-------+ +-----+ |mark + / | | 1 2 3 | | | | | | +--------------+ +-------+-------+-------+-------+ +-----+ |mark + | | / | 1 2 3 | | | | | +--------------+ +-------+-------+-------+-------+ +-----+ |mark | | + | / | 1 2 3 | | | | +--------------+ +-------+-------+-------+-------+ +-----+ | | | mark | + | / | 1 2 3 | |adv | +--------------+ +-------+-------+-------+-------+ +-----+ | | | mark | +/ | 1 2 3 | | |monad| +--------------+ +-------+-------+-------+-------+ +-----+ | | | mark | 6 | | | | | +--------------+ +-------+-------+-------+-------+ +-----+ A1.3.5 Conjunction RuleThe scheme is: conjunction EAVN VN1 CONJ VN1 etc => EAVN Z etc where Z is the result of applying conjunction CONJ to arguments VN1 and VN2. For example:
hist '' Queue Stack Rule +------------+ +------+-----+---+---+---+ +-----+ |mark 1 & + 2| | | | | | | | | +------------+ +------+-----+---+---+---+ +-----+ |mark 1 & + | | 2 | | | | | | | +------------+ +------+-----+---+---+---+ +-----+ |mark 1 & | | + | 2 | | | | | | +------------+ +------+-----+---+---+---+ +-----+ |mark 1 | | & | + | 2 | | | | | +------------+ +------+-----+---+---+---+ +-----+ |mark | | 1 | & | + | 2 | | | | +------------+ +------+-----+---+---+---+ +-----+ | | | mark | 1 | & | + | 2 | |conj | +------------+ +------+-----+---+---+---+ +-----+ | | | mark | 1&+ | 2 | | | |monad| +------------+ +------+-----+---+---+---+ +-----+ | | | mark | 3 | | | | | | +------------+ +------+-----+---+---+---+ +-----+ A1.3.6 Trident RuleThe scheme is: trident rule: EAVN VN1 VERB2 VERB3 etc => EAVN Z etc and there are two cases: VN1 may be a verb or a noun. If VN1 is the verb VERB1 then Z is the single verb defined as the fork VERB1 VERB2 VERB3. If VN1 is the noun NOUN1 then Z is the single verb defined as the abbreviation for a fork NOUN1 VERB2 VERB3. Forks and abbreviations for forks are described in Chapter 09. Here is an example: 1 + *: is an abbreviation for the fork 1: + *:
hist '' Queue Stack Rule +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark ( 1 + *: ) 2 3| | | | | | | | | | +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark ( 1 + *: ) | | 2 3 | | | | | | | | +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark ( 1 + *: | | ) | 2 3 | | | | | | | +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark ( 1 + | | *: | ) | 2 3| | | | | | +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark ( 1 | | + | *: | ) | 2 3| | | | | +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark ( | | 1 | + | *: | ) | 2 3| | | | +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark | | ( | 1 | + | *: | ) | 2 3| |trident| +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark | | ( | 1 + *:| ) | 2 3| | | |paren | +-------------------+ +-------+-------+----+----+----+----+ +-------+ |mark | | 1 + *:| 2 3 | | | | | | | +-------------------+ +-------+-------+----+----+----+----+ +-------+ | | | mark | 1 + *:| 2 3| | | | |monad | +-------------------+ +-------+-------+----+----+----+----+ +-------+ | | | mark | 5 10 | | | | | | | +-------------------+ +-------+-------+----+----+----+----+ +-------+ A1.3.7 Bident RuleThe scheme is: bident rule: EDGE CAVN1 CAVN2 etc => EDGE Z etc and there are altogether these 6 cases for the bident rule:
The first case (the hook) is described in Chapter 03 and the remaining cases in the schemes for bidents in Chapter 15. In the following example the expression (1 &) is a bident of the form noun conjunction. Therefore it is an adverb.
hist '' Queue Stack Rule +----------------+ +------+-----+----+---+---+ +------+ |mark + ( 1 & ) 2| | | | | | | | | +----------------+ +------+-----+----+---+---+ +------+ |mark + ( 1 & ) | | 2 | | | | | | | +----------------+ +------+-----+----+---+---+ +------+ |mark + ( 1 & | | ) | 2 | | | | | | +----------------+ +------+-----+----+---+---+ +------+ |mark + ( 1 | | & | ) | 2 | | | | | +----------------+ +------+-----+----+---+---+ +------+ |mark + ( | | 1 | & | ) | 2 | | | | +----------------+ +------+-----+----+---+---+ +------+ |mark + | | ( | 1 | & | ) | 2 | |bident| +----------------+ +------+-----+----+---+---+ +------+ |mark + | | ( | 1& | ) | 2 | | |paren | +----------------+ +------+-----+----+---+---+ +------+ |mark + | | 1& | 2 | | | | | | +----------------+ +------+-----+----+---+---+ +------+ |mark | | + | 1& | 2 | | | | | +----------------+ +------+-----+----+---+---+ +------+ | | | mark | + | 1& | 2 | | |adv | +----------------+ +------+-----+----+---+---+ +------+ | | | mark | 1&+ | 2 | | | |monad | +----------------+ +------+-----+----+---+---+ +------+ | | | mark | 3 | | | | | | +----------------+ +------+-----+----+---+---+ +------+ A1.3.8 Assignment RuleWe write NN to denote a noun or a name. and Asgn for the assignment symbol =: or =.. The scheme is: assign rule: NN Asgn CAVN etc => Z etc where Z is the value of CAVN.
hist '' Queue Stack Rule +---------------+ +------+----+---+---+ +------+ |mark 1 + x =: 6| | | | | | | | +---------------+ +------+----+---+---+ +------+ |mark 1 + x =: | | 6 | | | | | | +---------------+ +------+----+---+---+ +------+ |mark 1 + x | | =: | 6 | | | | | +---------------+ +------+----+---+---+ +------+ |mark 1 + | | x | =: | 6 | | |assign| +---------------+ +------+----+---+---+ +------+ |mark 1 + | | 6 | | | | | | +---------------+ +------+----+---+---+ +------+ |mark 1 | | + | 6 | | | | | +---------------+ +------+----+---+---+ +------+ |mark | | 1 | + | 6 | | | | +---------------+ +------+----+---+---+ +------+ | | | mark | 1 | + | 6 | |dyad | +---------------+ +------+----+---+---+ +------+ | | | mark | 7 | | | | | +---------------+ +------+----+---+---+ +------+ A1.3.9 Parenthesis RuleThe scheme is: paren rule: ( CAVN ) etc => Z etc where Z is the value of CAVN. For example:
hist '' Queue Stack Rule +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark ( 1 + 2 ) * 3| | | | | | | | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark ( 1 + 2 ) * | | 3 | | | | | | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark ( 1 + 2 ) | | * | 3 | | | | | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark ( 1 + 2 | | ) | * | 3 | | | | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark ( 1 + | | 2 | ) | * | 3 | | | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark ( 1 | | + | 2 | ) | * | 3 | | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark ( | | 1 | + | 2 | ) | * | 3 | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark | | ( | 1 | + | 2 | ) | * | 3 | |dyad | +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark | | ( | 3 | ) | * | 3 | | | |paren| +------------------+ +------+---+---+---+---+---+---+ +-----+ |mark | | 3 | * | 3 | | | | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ | | | mark | 3 | * | 3 | | | | |dyad | +------------------+ +------+---+---+---+---+---+---+ +-----+ | | | mark | 9 | | | | | | | | +------------------+ +------+---+---+---+---+---+---+ +-----+ A1.3.10 Examples of TransferThe following example shows that when a name is transferred from queue to stack, if the name denotes a value which is a noun, then the value, not the name, moves to the queue.
hist '' Queue Stack Rule +-------------------+ +------+-----+---+---+---+---+ +------+ |mark ( a =: 7 ) , a| | | | | | | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ |mark ( a =: 7 ) , | | 6 | | | | | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ |mark ( a =: 7 ) | | , | 6 | | | | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ |mark ( a =: 7 | | ) | , | 6 | | | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ |mark ( a =: | | 7 | ) | , | 6 | | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ |mark ( a | | =: | 7 | ) | , | 6 | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ |mark ( | | a | =: | 7 | ) | , | 6 | |assign| +-------------------+ +------+-----+---+---+---+---+ +------+ |mark ( | | 7 | ) | , | 6 | | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ |mark | | ( | 7 | ) | , | 6 | | |paren | +-------------------+ +------+-----+---+---+---+---+ +------+ |mark | | 7 | , | 6 | | | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ | | | mark | 7 | , | 6 | | | |dyad | +-------------------+ +------+-----+---+---+---+---+ +------+ | | | mark | 7 6 | | | | | | | +-------------------+ +------+-----+---+---+---+---+ +------+ By contrast, if the name is that of a verb, then the name is transferred into the stack without evaluating it. Hence a subsequent assignment changes the verb applied.
hist '' Queue Stack Rule +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( f =: - ) , f ) 4| | | | | | | | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( f =: - ) , f ) | | 4 | | | | | | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( f =: - ) , f | | ) | 4 | | | | | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( f =: - ) , | | f | ) | 4| | | | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( f =: - ) | | , | f | )| 4| | | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( f =: - | | ) | , | f| )| 4| | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( f =: | | - | ) | ,| f| )| 4| | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( f | | =: | - | )| ,| f| )| 4| | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( | | f | =: | -| )| ,| f| )| 4| |assign | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( ( | | - | ) | ,| f| )| 4| | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( | | ( | - | )| ,| f| )| 4| | |paren | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark ( | | - | , | f| )| 4| | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark | | ( | - | ,| f| )| 4| | | |trident| +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark | | ( | - , f| )| 4| | | | | |paren | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ |mark | | - , f| 4 | | | | | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ | | | mark | - , f| 4| | | | | | |monad | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ | | | mark | _4 _4| | | | | | | | | +-------------------------+ +------+------+--+--+--+--+--+--+ +-------+ A1.3.11 Review of Parsing Rules
A1.4 Effects of Parsing RulesNow we look at some of the effects, of the parsing rules. In what follows, notice how the parsing rules in effect give rise to implicit parentheses. A1.4.1 Dyad Has Long Right ScopeConsider the expression 4+3-2, which means 4+(3-2).
hist '' Queue Stack Rule +--------------+ +------+---+---+---+ +----+ |mark 4 + 3 - 2| | | | | | | | +--------------+ +------+---+---+---+ +----+ |mark 4 + 3 - | | 2 | | | | | | +--------------+ +------+---+---+---+ +----+ |mark 4 + 3 | | - | 2 | | | | | +--------------+ +------+---+---+---+ +----+ |mark 4 + | | 3 | - | 2 | | | | +--------------+ +------+---+---+---+ +----+ |mark 4 | | + | 3 | - | 2 | |dyad| +--------------+ +------+---+---+---+ +----+ |mark 4 | | + | 1 | | | | | +--------------+ +------+---+---+---+ +----+ |mark | | 4 | + | 1 | | | | +--------------+ +------+---+---+---+ +----+ | | | mark | 4 | + | 1 | |dyad| +--------------+ +------+---+---+---+ +----+ | | | mark | 5 | | | | | +--------------+ +------+---+---+---+ +----+ Here we have an example of a general rule: a dyadic verb takes as its right argument as much as possible, so in this example + is applied to 3-2, not just 3. Further, a dyadic verb takes as left argument as little as possible. In this example the left argument of - is just 3, not 4+3. Hence a dyadic verb is said to have a "long right scope" and a "short left scope". A1.4.2 Operators Before VerbsAdverbs and conjunctions get applied first, and then the resulting verbs:
hist '' Queue Stack Rule +--------------+ +------+-----+-----+---+---+---+ +------+ |mark * & 1 % 2| | | | | | | | | | +--------------+ +------+-----+-----+---+---+---+ +------+ |mark * & 1 % | | 2 | | | | | | | | +--------------+ +------+-----+-----+---+---+---+ +------+ |mark * & 1 | | % | 2 | | | | | | | +--------------+ +------+-----+-----+---+---+---+ +------+ |mark * & | | 1 | % | 2 | | | | | | +--------------+ +------+-----+-----+---+---+---+ +------+ |mark * | | & | 1 | % | 2 | | | | | +--------------+ +------+-----+-----+---+---+---+ +------+ |mark | | * | & | 1 | % | 2 | | | | +--------------+ +------+-----+-----+---+---+---+ +------+ | | | mark | * | & | 1 | % | 2 | |conj | +--------------+ +------+-----+-----+---+---+---+ +------+ | | | mark | *&1 | % | 2 | | | |monad2| +--------------+ +------+-----+-----+---+---+---+ +------+ | | | mark | *&1 | 0.5 | | | | |monad | +--------------+ +------+-----+-----+---+---+---+ +------+ | | | mark | 0.5 | | | | | | | +--------------+ +------+-----+-----+---+---+---+ +------+ A1.4.3 Operators Have Long Left ScopeIn the following examples, note that values of verbs are shown in the "parenthesized representation" (see Chapter 27) to show their structure. An adverb or a conjunction takes as its left argument as much as possible. Look at the structure of these verbs: evidently the / adverb and the @ conjunction take everything to their left:
hist '' Queue Stack Rule +--------------+ +------+---------+---+---+---+---+ +----+ |mark f & g @ h| | | | | | | | | | +--------------+ +------+---------+---+---+---+---+ +----+ |mark f & g @ | | h | | | | | | | | +--------------+ +------+---------+---+---+---+---+ +----+ |mark f & g | | @ | h | | | | | | | +--------------+ +------+---------+---+---+---+---+ +----+ |mark f & | | g | @ | h | | | | | | +--------------+ +------+---------+---+---+---+---+ +----+ |mark f | | & | g | @ | h | | | | | +--------------+ +------+---------+---+---+---+---+ +----+ |mark | | f | & | g | @ | h | | | | +--------------+ +------+---------+---+---+---+---+ +----+ | | | mark | f | & | g | @ | h | |conj| +--------------+ +------+---------+---+---+---+---+ +----+ | | | mark | f&g | @ | h | | | |conj| +--------------+ +------+---------+---+---+---+---+ +----+ | | | mark | (f&g)@h | | | | | | | +--------------+ +------+---------+---+---+---+---+ +----+ Thus operators are said to have a "long left scope". In the example of f&g@h we see that the right argument of & is just g, not g@h . Thus conjunctions have "short right scope". A1.4.4 Train on the LeftThe long left scope of an adverb does not extend through a train: parentheses may be needed to get the desired effect. Suppose f g h is intended as a train, then compare the following:
hist '' Queue Stack Rule +------------+ +------+----------+----+----+ +-------+ |mark f g h /| | | | | | | | +------------+ +------+----------+----+----+ +-------+ |mark f g h | | / | | | | | | +------------+ +------+----------+----+----+ +-------+ |mark f g | | h | / | | | | | +------------+ +------+----------+----+----+ +-------+ |mark f | | g | h | / | | |adv | +------------+ +------+----------+----+----+ +-------+ |mark f | | g | h/ | | | | | +------------+ +------+----------+----+----+ +-------+ |mark | | f | g | h/ | | | | +------------+ +------+----------+----+----+ +-------+ | | | mark | f | g | h/ | |trident| +------------+ +------+----------+----+----+ +-------+ | | | mark | f g (h/) | | | | | +------------+ +------+----------+----+----+ +-------+ Similarly for a conjunction (with a right argument)
hist '' Queue Stack Rule +--------------+ +------+-----------+-----+-----+ +-------+ |mark f g h @ +| | | | | | | | +--------------+ +------+-----------+-----+-----+ +-------+ |mark f g h @ | | + | | | | | | +--------------+ +------+-----------+-----+-----+ +-------+ |mark f g h | | @ | + | | | | | +--------------+ +------+-----------+-----+-----+ +-------+ |mark f g | | h | @ | + | | | | +--------------+ +------+-----------+-----+-----+ +-------+ |mark f | | g | h | @ | + | |conj | +--------------+ +------+-----------+-----+-----+ +-------+ |mark f | | g | h@+ | | | | | +--------------+ +------+-----------+-----+-----+ +-------+ |mark | | f | g | h@+ | | | | +--------------+ +------+-----------+-----+-----+ +-------+ | | | mark | f | g | h@+ | |trident| +--------------+ +------+-----------+-----+-----+ +-------+ | | | mark | f g (h@+) | | | | | +--------------+ +------+-----------+-----+-----+ +-------+ However, for a conjunction with no right argument, the left scope does extend through a train:
hist '' Queue Stack Rule +------------+ +------+----------+---+---+---+ +-------+ |mark f g h @| | | | | | | | | +------------+ +------+----------+---+---+---+ +-------+ |mark f g h | | @ | | | | | | | +------------+ +------+----------+---+---+---+ +-------+ |mark f g | | h | @ | | | | | | +------------+ +------+----------+---+---+---+ +-------+ |mark f | | g | h | @ | | | | | +------------+ +------+----------+---+---+---+ +-------+ |mark | | f | g | h | @ | | | | +------------+ +------+----------+---+---+---+ +-------+ | | | mark | f | g | h | @ | |trident| +------------+ +------+----------+---+---+---+ +-------+ | | | mark | f g h | @ | | | |bident | +------------+ +------+----------+---+---+---+ +-------+ | | | mark | (f g h)@ | | | | | | +------------+ +------+----------+---+---+---+ +-------+ By contrast, in the case of of f @ g /, notice how the "conj" rule is applied before there is a chance to apply the "adverb" rule"
hist '' Queue Stack Rule +------------+ +------+--------+---+---+---+ +----+ |mark f @ g /| | | | | | | | | +------------+ +------+--------+---+---+---+ +----+ |mark f @ g | | / | | | | | | | +------------+ +------+--------+---+---+---+ +----+ |mark f @ | | g | / | | | | | | +------------+ +------+--------+---+---+---+ +----+ |mark f | | @ | g | / | | | | | +------------+ +------+--------+---+---+---+ +----+ |mark | | f | @ | g | / | | | | +------------+ +------+--------+---+---+---+ +----+ | | | mark | f | @ | g | / | |conj| +------------+ +------+--------+---+---+---+ +----+ | | | mark | f@g | / | | | |adv | +------------+ +------+--------+---+---+---+ +----+ | | | mark | (f@g)/ | | | | | | +------------+ +------+--------+---+---+---+ +----+ A1.4.5 Presumption of VerbA name with no value assigned is presumed to be a verb. For example, in the following the two names make a hook:
hist '' Queue Stack Rule +---------------+ +-------+------------+-------+ +------+ |mark Blue Skies| | | | | | | +---------------+ +-------+------------+-------+ +------+ |mark Blue | | Skies | | | | | +---------------+ +-------+------------+-------+ +------+ |mark | | Blue | Skies | | | | +---------------+ +-------+------------+-------+ +------+ | | | mark | Blue | Skies | |bident| +---------------+ +-------+------------+-------+ +------+ | | | mark | Blue Skies | | | | +---------------+ +-------+------------+-------+ +------+ This is the end of Appendix 1. |
The examples in this chapter
were executed using J version 701.
This chapter last updated 29 Jul 2012
Copyright © Roger Stokes 2012.
This material may be freely reproduced,
provided that this copyright notice is also reproduced.
>> << Pri JfC LJ Phr Dic Voc !: Rel NuVoc wd Help Learning J