|
|
1.1 ! root 1: .NH 1 ! 2: The State Indicator ! 3: .PP ! 4: \*a is a recursive language ! 5: which supports local variables. ! 6: Therefore, ! 7: it is essential that it ! 8: maintain some sort of information ! 9: concerning its current state of ! 10: execution, ! 11: local variables, ! 12: and status of functions. ! 13: Part of this information \(em ! 14: the current status of active ! 15: functions, ! 16: is called the ``state indicator''.* ! 17: .FS ! 18: *Users of other \*a systems ! 19: should note that ! 20: the state indicator as implemented on ! 21: \*u \*a is similar in concept ! 22: to the standard \*a state ! 23: indicator, ! 24: but does not function entirely the same ! 25: way. ! 26: In particular, ! 27: the system command ``)siv'' is not supported, ! 28: and the state indicator is cleared in ! 29: a different manner. ! 30: Read on. ! 31: .FE ! 32: Each time a function begins execution, ! 33: \*a keeps track of the current line ! 34: number in that function. ! 35: When the current function calls ! 36: another function, ! 37: the line number where the request ! 38: was made is recorded in the ! 39: state indicator. ! 40: .PP ! 41: When a function terminates abnormally, ! 42: it is said to be ``suspended''. ! 43: This means that \*a stops execution ! 44: of the function, ! 45: but retains all information about its ! 46: current state of execution. ! 47: In some cases, ! 48: the problem can be corrected and the ! 49: function restarted where it left off. ! 50: This discussion will not include that ! 51: technique. ! 52: In any event, ! 53: when the function is suspended, ! 54: \*a will print a traceback automatically, ! 55: perhaps such as: ! 56: .sp ! 57: .DS L ! 58: varx: used before set ! 59: at fn3[5] ! 60: from fn2[12] ! 61: from main[4] ! 62: .DE ! 63: .sp ! 64: In this case, ! 65: the error ! 66: (undefined variable) ! 67: occurred in the function ! 68: ``fn3'' at line 5. ! 69: ``fn3'' was called by the ! 70: function ``fn2'' at line 12, ! 71: which in turn was called by the ! 72: function ``main'' at line 14. ! 73: .PP ! 74: The ``)si'' command produces a similar ! 75: traceback. ! 76: For the above example, ! 77: the traceback could be: ! 78: .sp ! 79: .DS L ! 80: fn3[5] * ! 81: fn2[12] ! 82: main[4] ! 83: .DE ! 84: .sp ! 85: This shows that the function ! 86: ``fn3'' was suspended due to error, ! 87: and that ``fn2'' and ``main'' are ! 88: waiting for ``fn3'' and ``fn2'', ! 89: respectively. ! 90: .PP ! 91: When an error occurs and a ! 92: function is suspended, ! 93: all of that function's variables ! 94: are accessible from the keyboard. ! 95: Thus, ! 96: you can examine the current ! 97: variables to help determine the problem. ! 98: As stated above, ! 99: in some cases it may be ! 100: possible to change some variables ! 101: and resume execution of the suspended ! 102: function. ! 103: However, ! 104: in general, ! 105: after you examine the variables ! 106: you will probably want to restart ! 107: from the beginning. ! 108: In order to do this, ! 109: type the ``)reset'' command. ! 110: This causes \*a to clear the ! 111: state indicator, ! 112: resetting suspended functions ! 113: and releasing local variables. ! 114: .PP ! 115: If you do not use ``)reset'', ! 116: you will find two things. ! 117: First, ! 118: if you get another error, ! 119: the state indicator may look like: ! 120: .sp ! 121: .DS L ! 122: fn3[3] * ! 123: fn2[12] ! 124: main[4] ! 125: fn3[5] * ! 126: fn2[12] ! 127: main[4] ! 128: .DE ! 129: .sp ! 130: This shows that ``fn3'' was suspended ! 131: due to an error at line 3, ! 132: and it traces execution back to ! 133: the start of ``main''. ! 134: Then, ! 135: it shows that in a previous run, ! 136: ``fn3'' was suspended due to an error ! 137: at line 5, ! 138: and it traces execution back to ! 139: the start of ``main''. ! 140: You can still use the ``)reset'' ! 141: command to get back to a clear ! 142: state indicator. ! 143: .PP ! 144: The other effect which you will ! 145: notice if you do not ``)reset'' ! 146: the state indicator is that ! 147: you will be unable to edit some ! 148: functions. ! 149: If a function is suspended ! 150: (it appears in the state indicator), ! 151: it cannot be changed, ! 152: because it is possible that ! 153: the error condition may be corrected ! 154: and execution resumed. ! 155: Therefore, ! 156: if you try to edit a function which ! 157: appears in the state indicator, ! 158: you will get the error message: ! 159: .sp ! 160: si damage -- type \')reset\' ! 161: .sp ! 162: To edit the function, ! 163: clear the state indicator with ! 164: ``)reset'' first, ! 165: and then you may proceeed with ! 166: an ``)edit'' or ``)editf'' command. ! 167: .PP ! 168: A useful technique for finding ! 169: errors is to look at the function ! 170: which ``blew up'' and try retyping ! 171: the line which failed, ! 172: a little bit at a time. ! 173: This often helps isolate the ! 174: problem. ! 175: Generally, ! 176: you want to do this before the ! 177: state indicator is ``)reset'' ! 178: so that the state of \*a is ! 179: exactly the same as it was when ! 180: the error was detected. ! 181: Since you cannot run the editor ! 182: to list the function ! 183: without typing ``)reset'', ! 184: you will probably want to use ! 185: the ``)list'' command ! 186: to look at the bad function. ! 187: .PP ! 188: As an example, ! 189: suppose your ``friend'' Chris ! 190: (male or female, ! 191: take your pick) ! 192: gave you the following program ! 193: to compute the reciprocal of ! 194: the numbers from 1 to x: ! 195: .DS L ! 196: r { recip x ! 197: [1] r { % Ix ! 198: .DE ! 199: You are using origin 0, ! 200: and ! 201: your attempt to run the ! 202: function yields the following: ! 203: .DS L ! 204: recip 10 ! 205: recip domain ! 206: at recip[1] ! 207: .DE ! 208: It looks like Chris gave ! 209: you a bum steer. ! 210: You decide to try to debug ! 211: the function. ! 212: You can't use the editor ! 213: to look at it with ``)editf'' ! 214: unless you type ``)reset'' first. ! 215: You don't want to ``)reset'', ! 216: because that would take you ! 217: back to the beginning and ! 218: you would lose any ! 219: temporary variables ! 220: (in this case, just ``x''). ! 221: Thus, ! 222: you can use the ``)list'' command: ! 223: .DS L ! 224: )list recip ! 225: ! 226: y { recip x ! 227: [1] y { %Ix ! 228: .DE ! 229: Now, ! 230: you can experiment with the ! 231: function by typing the commands ! 232: yourself: ! 233: .DS L ! 234: x ! 235: 10 ! 236: ! 237: Ix ! 238: 0 1 2 3 4 5 6 7 8 9 ! 239: .DE ! 240: At this point, ! 241: you immediately spot the ! 242: trouble \(em ! 243: \*a was trying to take the ! 244: reciprocal of 0. ! 245: The function ``recip'' was ! 246: written assuming that the ! 247: origin was 1, ! 248: but Chris did not tell you ! 249: and you were using 0 instead. ! 250: Thus, ! 251: you merely say: ! 252: .DS L ! 253: )reset ! 254: .DE ! 255: (now that you've found the problem, ! 256: you want to reset \*a to clear the ! 257: state indicator), ! 258: and ! 259: .DS L ! 260: )origin 1 ! 261: was 0 ! 262: ! 263: recip ! 264: 1.00000000e+00 5.00000000e\(mi01 3.33333333e\(mi01 2.50000000e\(mi01 ! 265: 2.00000000e\(mi01 1.66666667e\(mi01 1.42857143e\(mi01 ! 266: 1.25000000e\(mi01 1.11111111e\(mi01 1.00000000e\(mi01 ! 267: .DE
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.