home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pop / 221 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  2.7 KB

  1. Path: sparky!uunet!olivea!charnel!sifon!thunder.mcrcim.mcgill.edu!sobeco!philmtl!ray
  2. From: ray@philmtl.philips.ca (Ray Dunn)
  3. Newsgroups: comp.lang.pop
  4. Subject: Re: dlocals etc. (and shallow binding)
  5. Message-ID: <1993Jan26.033934.12517@philmtl.philips.ca>
  6. Date: 26 Jan 93 03:39:34 GMT
  7. References: <58946@dime.cs.umass.edu> <C1CAwq.8up@cs.bham.ac.uk>
  8. Organization: Not Philips.
  9. Lines: 59
  10.  
  11. In refd article, axs@cs.bham.ac.uk (Aaron Sloman) writes:
  12. >A really "clean" implementation would have required all local
  13. >variables to have their values initialised to some safe default on
  14. >procedure entry, e.g. to "undef".
  15.  
  16. ..and to take advantage of internal knowledge of the fact that it doesn't
  17. raises the hackles of anyone concerned about "future release surprise" or
  18. portability!
  19.  
  20. >    define print_procedure( ..... );
  21. >        dlocal printlevel = printlevel + 1;
  22.  
  23.  
  24. looks pretty bogus to me.  I've been trying to teach programmers to avoid
  25. this sort of thing for years.  POP-2 was quite clear about it, even though
  26. this code would "work".  The reference manual states that when the extent
  27. of another variable is interrupted "its value is not altered but it cannot
  28. be accessed or changed by assignment."
  29.  
  30. >The alternative to these dynamically scoped uses of printlevel and
  31. >popmatchvars (and similar things, like interrupt, cucharout,
  32. >prmishap, etc.) would have been to require all these values to be
  33. >passed explicitly as extra arguments in any procedure that might
  34. >call a procedure that used these values, or else to do what Robin
  35. >does, namely:
  36. >
  37. >> My own practice these days is to avoid any dlocals in code I actually
  38. >> write, by using an extra argument to any function (usually called "Env")
  39. >> which is a data-structure that bundles up any kind of style switch.
  40.  
  41. In 'C' the effect can often be achieved by using a _static_ variable, but
  42. my own technique is to use a pair of functions - the outer function
  43. presents a "clean" interface to the outside world and calls a second
  44. function with all the required extra arguments - it is this second function
  45. that recurses.
  46.  
  47. So Aaron's example becomes (ha! I'll do it in POP-2ish)
  48.  
  49.     vars max_printlevel;
  50.     5 -> max_printlevel;
  51.  
  52.     print_procedure(....)
  53.         aux_print_proc(..... , 1);
  54.     end
  55.  
  56.     aux_print_proc(..... , printlevel)
  57.  
  58.         if printlevel >= max_printlevel then
  59.             ... print closing bracket and return ....
  60.         else
  61.             ... print suitable opening bracket ....
  62.             aux_print_proc(whatever tail of structure, printlevel+1);
  63.         close
  64.     end
  65.  
  66. Now who has a compiler I can syntax check this with!!
  67. -- 
  68. Ray Dunn at home        |  Beaconsfield, Quebec  |  Phone: (514) 630 3749
  69. ray@philmtl.philips.ca  |  ray@cam.org           |  uunet!sobeco!philmtl!ray
  70.