next up previous contents index
Next: Redirecting output Up: Subroutines and external files Previous: Unconditionally switching program flow

Temporarily diverting program flow to subroutines

   


tex2html_wrap_inline33790 tex2html_wrap_inline33790 Syntax

  1. BD>m : @L tex2html_wrap_inline33712

  2. BD>m : @L(C) tex2html_wrap_inline33712

  3. BD>m : (C) tex2html_wrap_inline33712

where L is the name of a label and C is a valid input channel number.

tex2html_wrap_inline33806 tex2html_wrap_inline33806

The M:  command is used to divert program flow to a subroutine. Typically, once the subroutine has been processed, program flow resumes at the line beyond the line containing the M:  command (or control returns to the keyboard). Most subroutines are terminated by a RETURN:  command, or by and end-of-file marker with similar consequences. This command is thus the similar to the GOTO:  command except that it is linked with a RETURN:  command.

If the first form of the command is issued, with no channel number being specified, the channel number is deduced - [B/D] does not allow duplicate labels. In the third form of the syntax, the beginning of the file associated with the input channel is indicated. In common with other macro facilities, the channel number can be zero (meaning the keyboard): a label should not be supplied in this case. The channel and label specified or implied must exist at the time the command is issued.

Technically, [B/D] maintains a stack of program diversions and return addresses. The return address is the line beyond the line containing the M:  command if the command was issued from a macro file, or otherwise the return address amounts to returning control to the keyboard. The stack of return addresses may grow as large as machine memory will allow, meaning that you may nest subroutines as deeply as you wish. The RETURN:  command acts as an end to the diversion or subroutine, and an end-of-file marker also acts in this way. In either of these circumstances, the return address stack diminishes one level, and control is passed back to the situation holding before the corresponding M:  command was issued.

Although we tend to use the M:  and RETURN:  commands for the creation of separate program modules, this is not forced. You may use or misuse the M:  command as you see fit. The CLEARRETURNS:  command may be used to clear the return address stack if necessary. The return address stack is automatically cleared when a RESTART:  command is issued, but not when a CLEAR:  command is issued.

Commands which might result in diverting program flow (GOTO: , M: , and RETURN: ) must be issued on a separate line; otherwise an error is reported. Hence the following usage is not permitted:

BD>for : i=1,1,2 tex2html_wrap_inline33876 m : @test[i] tex2html_wrap_inline33712

The following fragments of code show three examples.

BD>m : @oporto tex2html_wrap_inline33712

BD>m : @oporto(2) tex2html_wrap_inline33712

BD>m : (2) tex2html_wrap_inline33712

The first example refers explicitly to the label ``@oporto''. No channel number is given, so [B/D] will search all the input channels for a match. There may be at most one match as [B/D] does not permit duplicate labels. The address thus consists of the given label, on a channel which will be deduced. In the second example, the address consists explicitly of a label and a channel number. In the third example, no label is given, and the top of the external file associated with input channel number 2 will be assumed as the required address. For each usage the return address will be the same, and as soon as the subroutine has been processed and a RETURN:  command or end-of-file marker encountered, program flow will return to this point.  


next up previous contents index
Next: Redirecting output Up: Subroutines and external files Previous: Unconditionally switching program flow

David Wooff
Wed Oct 21 15:14:31 BST 1998