!goto - Unconditional Jump
!goto label
n !goto
Flow can be controlled within a MicroEmacs '99 macro using the !goto directive. It takes as an argument a label. A label consists of a line starting with an asterisk (*) and then an alphanumeric label. Only labels in the currently executing macro can be jumped to, and trying to jump to a non-existing label terminates execution of a macro. labels may be located at any position within the macro (forwards or backwards from the !goto).
The second form of the !goto, (which is more efficient than the labeled jump), may be passed an integer value containing a signed relative displacement n. n may be a literal numeric value, a variable or an evaluated expression (see Variable Functions). The displacement to jump starts from the current !goto line. (i.e. 0 goto) would loop forever as it jumps to itself). Negative n branches backwards, positive n forwards.
For example, create a block of DATA statements for a BASIC program:
insert-string "1000 DATA " set-variable %linenum 1000 *nxtin screen-update ;make sure we see the changes set-variable %data @ml"Next number: " !if &equal %data 0 !goto finish !endif !if &greater $curcol 60 2 backward-delete-char newline set-variable %linenum &add %linenum 10 insert-string &cat %linenum " DATA " !endif insert-string &cat %data ", " !goto nxtin *finish 2 backward-delete-char newline
Not that any of us are writing basic programs these days !!
For some serious dirty macro tricks then the numerical version of the !goto directive becomes very useful. The following example is taken from the Metris macro (which is packed with goodies if you can find time to work out what it does !!). The following example uses the random number generator $random(5) to generate a random number which scaled and used as a !goto offset, thereby creating a switch type statement.
0 define-macro met-select-piece &mul 5 &add 1 &div &mod $random 71 10 !goto set-variable :met-np1 " X " ; 1st 3 lines are dummies to get offset right set-variable :met-np1 " X " set-variable :met-np1 " X " set-variable :met-np1 " X " set-variable :met-np1 " X " set-variable :met-np2 "XX " set-variable :met-np3 " X " set-variable :met-ncol %lyellow !return set-variable :met-np1 "XX " set-variable :met-np2 "XX " set-variable :met-np3 " " set-variable :met-ncol %yellow !return set-variable :met-np1 "X " set-variable :met-np2 "XX " set-variable :met-np3 " X " set-variable :met-ncol %lmagenta !return set-variable :met-np1 " X" set-variable :met-np2 " XX" set-variable :met-np3 " X " set-variable :met-ncol %lgreen !return set-variable :met-np1 " X " set-variable :met-np2 " X " set-variable :met-np3 " XX" set-variable :met-ncol %magenta !return set-variable :met-np1 " X " set-variable :met-np2 " X " set-variable :met-np3 "XX " set-variable :met-ncol %green !return set-variable :met-np1 " X " set-variable :met-np2 " X " set-variable :met-np3 " X " set-variable :met-ncol %lblue !return set-variable :met-np1 " X " set-variable :met-np2 " X " set-variable :met-np3 "X X" set-variable :met-ncol %lred !emacro
(c) Copyright JASSPA 1999
Last Modified: 1998/09/13
Generated On: 1999/07/16