home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / misc / 2737 < prev    next >
Encoding:
Text File  |  1992-08-19  |  3.0 KB  |  111 lines

  1. Newsgroups: comp.lang.misc
  2. Path: sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!zrz.tu-berlin.de!math.fu-berlin.de!Sirius.dfn.de!darwin.sura.net!zaphod.mps.ohio-state.edu!menudo.uh.edu!sugar!ficc!peter
  3. From: peter@ferranti.com (Peter da Silva)
  4. Subject: Re: PL/1 non-local goto versus setjmp/longjmp
  5. Message-ID: <id.KTGS.0N5@ferranti.com>
  6. Organization: Xenix Support, FICC
  7. References: <1992Aug12.073130.1@zodiac.rutgers.edu> <id.VJBS.0DK@ferranti.com> <mwm.1jk3@contessa.palo-alto.ca.us>
  8. Date: Tue, 18 Aug 1992 14:54:47 GMT
  9. Lines: 100
  10.  
  11. In article <mwm.1jk3@contessa.palo-alto.ca.us> mwm@contessa.palo-alto.ca.us (Mike Meyer) writes:
  12. > In <id.VJBS.0DK@ferranti.com>, peter@ferranti.com (Peter da Silva) wrote:
  13. > > Personally, I'd prefer if C had no goto at all, but an organized system of
  14. > > contexts, so you could perform setjmp/longjmp operations within a routine.
  15.  
  16. > I'm not quite sure what you mean by "organized system of contexts"? If
  17. > this mechanism would allows multilevel loop breaks. If not, I'd like
  18. > more details on it.
  19.  
  20. Basically, imagine integrating setjmp/longjmp with the language to a greater
  21. extent. Instead of writing:
  22.  
  23.     retry:
  24.         insert amazing mass of nested loops here {
  25.             goto retry;
  26.         }
  27.         and put in some more code here
  28.         if something horrible happens {
  29.             goto fail;
  30.         }
  31.         and still more code
  32.     fail:
  33.  
  34. You use a formal setup like so:
  35.  
  36.     context foo: {
  37.         insert amazing mass of nested loops here {
  38.             continue foo;
  39.         }
  40.         and put some more code here
  41.         if something horrible happens {
  42.             break foo;
  43.         }
  44.         and still more code
  45.     }
  46.  
  47. Now, to generalize:
  48.  
  49.     context foo;
  50.  
  51.     ...
  52.  
  53.     context foo: {
  54.         yadda yadda yadda
  55.         bar(foo);
  56.     }
  57.  
  58. void bar(foo)
  59. context foo;
  60. {
  61.     blah blah blah;
  62.     if something horrible happens {
  63.         break foo;
  64.     }
  65. }
  66.  
  67. But putting it directly in the language, you allow for more optimizations.
  68. By replacing goto, you clean up a messy part of the language without losing
  69. any general capability (switches with good optimization and this context
  70. can replace every use of goto).
  71.  
  72. As a further elaboration (my long-term fantasy, real coroutine support in C):
  73.  
  74.     context other, self;
  75.     stack_t otherstack[MIN_STACK + 20*STACK_FRAME + 20*30*sizeof(int)];
  76.     extern void token(context, context);
  77.  
  78.     bind other: otherstack, token, (self);
  79.     bind self;
  80.  
  81.     while((t = pause(other, 1)) != EOF) {
  82.         handle_token(t);
  83.         if we need to bail out
  84.             (void)pause(other, 0);
  85.     }
  86.  
  87.  
  88. token(other)
  89. context other;
  90. {
  91.     char buf[whatever];
  92.  
  93.     while(gets(buf)) {
  94.         parse tokens here;
  95.         if it looks like a foo
  96.             if(!pause(other, foo))
  97.                 break;
  98.         ...
  99.     }
  100. }
  101.  
  102. Yes, you can build subroutine libraries that do this, but they're inherently
  103. non-portable. This sort of thing should be part of the language, and is much
  104. more important to me than expanding the type structure with object-oriented
  105. stuff.
  106. -- 
  107. Peter da Silva                                               `-_-'
  108. $ EDIT/TECO LOVE                                              'U` 
  109. %TECO-W-OLDJOKE Not war?                        Have you hugged your wolf today?
  110. Ferranti Intl. Ctls. Corp.      Sugar Land, TX  77487-5012       +1 713 274 5180
  111.