Previous

5.4. Units associated with routines

{Routines are created from routine-texts {5.4.1 } or from jumps {5.4.4 }, and they may be "called" by calls {5.4.3 }, formulas {5.4.2} or by deproceduring {6.3 }.}

5.4.1. Routine texts

{A routine-text always has a formal-declarer, specifying the mode of the result, and a routine-token, viz., a colon. To the right of this colon stands a unit, which prescribes the computations to be performed when the routine is called. If there are parameters, then to the left of the formal-declarer stands a declarative containing the various formal-parameters required.

Examples:

VOID: print(x); (REF REAL a, REAL b)BOOL: (a < b | a := b; TRUE | FALSE) .}

5.4.1.1. Syntax

a) procedure yielding MOID NEST1 routine text{44d ,5A} : formal MOID NEST1 declarer{46b } , routine{94f} token, strong MOID NEST1 unit{32d } .

b) procedure with PARAMETERS yielding MOID NEST1 routine text{44d ,5A} : NEST1 new DECS2 declarative defining new DECS2{e} brief pack, where DECS2 like PARAMETERS{c,d,-}, formal MOID NEST1 declarer{46b } , routine{94f } token, strong MOID NEST1 new DECS2 unit{32d } .

c) WHETHER DECS DEC like PARAMETERS PARAMETER{b,c} : WHETHER DECS like PARAMETERS{c,d,-} and DEC like PARAMETER{d,-}. {PARAMETER :: MODE parameter.}

d) WHETHER MODE TAG like MODE parameter{b,c} : WHETHER true.

e) NEST2 declarative defining new DECS2{b,e,34j } : formal MODE NEST2 declarer{46b } , NEST2 MODE parameter joined definition of DECS2{41b,c } ; where (DECS2) is (DECS3 DECS4), formal MODE NEST2 declarer{46b } , NEST2 MODE parameter joined definition of DECS3{41b,c } , and also{94f } token, NEST2 declarative defining new DECS4{e}.

f) NEST2 MODE parameter definition of MODE TAG2{41c } : MODE NEST2 defining identifier with TAG2{48a } .

g) *formal MODE parameter : NEST MODE parameter definition of MODE TAG{f}. {Examples:

}

a)
REAL: random * 10
b)
(BOOL a, b)BOOL: (a | b | FALSE)
e)
BOOL a, b ·BOOL a, BOOL b
f)
a

5.4.1.2. Semantics

The yield of a routine-text T, in an environ E, is the routine composed of
  1. T, and
  2. the environ necessary for {7.2.2.c } T in E.

5.4.2. Formulas

{Formulas are either dyadic or monadic: e.g., x + i or ABS x. The order of elaboration of a formula is determined by the priority of its operators; monadic formulas are elaborated first and then the dyadic ones from the highest to the lowest priority.}

5.4.2.1. Syntax

A) DYADIC :: priority PRIO.

B) MONADIC :: priority iii iii iii i.

C) ADIC :: DYADIC ; MONADIC.

D) TALLETY :: TALLY ; EMPTY.

a) MOID NEST DYADIC formula{c,5B } : MODE1 NEST DYADIC TALLETY operand{c,-}, procedure with MODE1 parameter MODE2 parameter yielding MOID NEST applied operator with TAD{48b } , where DYADIC TAD identified in NEST{72a } , MODE2 NEST DYADIC TALLY operand{c,-}.

b) MOID NEST MONADIC formula{c,5B } : procedure with MODE parameter yielding MOID NEST applied operator with TAM {48b } , MODE NEST MONADIC operand{c}.

c) MODE NEST ADIC operand{a,b} : firm MODE NEST ADIC formula{a,b} coercee{61b } ; where (ADIC) is (MONADIC), firm MODE NEST SECONDARY{5C } .

d) *MOID formula : MOID NEST ADIC formula{a,b}.

e) *DUO dyadic operator with TAD : DUO NEST DEFIED operator with TAD{48a,b } .

f) *MONO monadic operator with TAM : MONO NEST DEFIED operator with TAM{48a,b } .

g) *MODE operand : MODE NEST ADIC operand{c}. {Examples:

}

a)
-x+1
b)
-x
c)
-x ·1

5.4.2.2. Semantics

The yield W of a formula F, in an environ E, is determined as follows:

· let R be the routine yielded in E by the operator of F;

· let V1, ... , Vn {n is 1 or 2} be the {collateral} yields of the operands of F, in an environ E1 established {locally, see 3.2.2.b } around E;

· W is the yield of the calling {5.4.3.2.b } of R in E1, with V1, ... , Vn;

· it is required that W be not newer in scope than E.

{Observe that a ^ b is not precisely the same as ab in the usual notation; indeed, the value of (- 1 ^ 2 + 4 = 5) and that of (4 - 1 ^ 2 = 3) both are true, since the first minus-symbol is a monadic-operator, whereas the second is a dyadic-operator.}

5.4.3. Calls

{Calls are used to command the elaboration of routines parametrized with actual-parameters.

Examples:

sin(x) ·(p | sin | cos)(x) .}

5.4.3.1. Syntax

a) MOID NEST call{5D } : meek procedure with PARAMETERS yielding MOID NEST PRIMARY{5D } , actual NEST PARAMETERS{b,c} brief pack.

b) actual NEST PARAMETERS PARAMETER{a,b} : actual NEST PARAMETERS{b,c}, and also{94f } token, actual NEST PARAMETER {c}.

c) actual NEST MODE parameter{a,b} : strong MODE NEST unit{32d } . {Examples:

}

a)
put(stand out, x) (see 10.3.3.1.a )
b)
stand out, x
c)
x

5.4.3.2. Semantics

a) The yield W of a call C, in an environ E, is determined as follows:

· let R {a routine} and V1, ... , Vn be the {collateral} yields of the PRIMARY of C, in E, and of the constituent actual-parameters of C, in an environ E1 established {locally, see 3.2.2.b } around E;

· W is the yield of the calling {b}of R in E1 with V1, ... , Vn;

· it is required that W be not newer in scope than E.

b) The yield W of the "calling", of a routine R in an environ E1, possibly with {parameter} values V1, ... , Vn, is determined as follows:

· let E2 be the environ established {3.2.2.b } upon E1, around the environ of R, according to the declarative of the declarative-pack, if any, of the routine-text of R, with the values V1, ... , Vn, if any;

· W is the yield in E2 of the unit of the routine-text of R.

{Consider the following serial-clause:

PROC samelson = (INT n, PROC(INT)REAL f)REAL:
  BEGIN LONG REAL s := LONG 0;
      FOR i TO n DO s +:= LENG f(i) ^ 2 OD;
      SHORTEN long sqrt(s)
  END;
samelson(m, (INT j)REAL: x1[j])
.
In that context, the last call has the same effect as the following cast:
REAL(
    INT n = m, PROC(INT)REAL f = (INT j)REAL: x1[j];
    BEGIN LONG REAL s := LONG 0;
        FOR i TO n DO s +:= LENG f(i) ^ 2 OD;
        SHORTEN long sqrt(s)
    END)
.
The transmission of actual-parameters is thus similar to the elaboration of identity-declarations {4.4.2.a }; see also establishment {3.2.2.b } and ascription {4.8.2.a}.}

5.4.4. Jumps

{A jump may terminate the elaboration of a series and cause some other labelled series to be elaborated in its place.

Examples:

y = IF x >= 0 THEN sqrt(x)ELSE GOTO princeton FI ·GOTO st pierre de chartreuse . Alternatively, if the context expects the mode 'procedure yielding MOID', then a routine whose unit is that jump is yielded instead, as in

PROC VOID m := GOTO north berwick .}

5.4.4.1. Syntax

a) strong MOID NEST jump{5A } : go to{b} option, label NEST applied identifier with TAG{48b } .

b) go to{a} : STYLE go to{94f ,-} token ; STYLE go{94f ,-} token, STYLE to symbol{94g,-}. {Examples:

}

a)
GOTO kootwijk ·GO TO warsaw ·zandvoort
b)
GOTO ·GO TO

5.4.4.2. Semantics

A MOID-NEST-jump J, in an environ E, is elaborated as follows:

· let the scene yielded in E by the label-identifier of J be composed of a series S2 and an environ E1;

Case A: 'MOID' is not any 'procedure yielding MOID1':


· let S1 be the series of the smallest {1.1.3.2.g } serial-clause containing S2;

· the elaboration of S1 in E1, or of any series in E1 elaborated in its place, is terminated {2.1.4.3.e };

· S2 in E1 is elaborated "in place of" S1 in E1;

Case B: 'MOID' is some 'procedure yielding MOID1':


· J in E {is completed and} yields the routine composed of

( 1) a new MOID-NEST-routine-text whose unit is akin {1.1.3.2.k } to J,
( 2) E1.


 
Next