In Common Lisp, multilevel returns use catch and throw; exception handling in the style of most other modern languages uses handler-case and
error. Show that the distinction between these is mainly a matter of style,
rather than expressive power. In other words, show that each facility can be
used to emulate the other.
#include #include #include
char* days[7] = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
char today[10];
void handler(int n) {
printf(" %s\n", today);
}
int main() {
signal(SIGTSTP, handler); // ^Z at keyboard
for(int n = 0; ; n++) {
strcpy(today, days[n%7]);
}
}
Figure 9.6 A problematic program in C to illustrate the use of signals. In most Unix systems,
the SIGTSTP signal is generated by typing control-Z at the keyboard.