home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pop / 95 < prev   
Encoding:
Text File  |  1992-11-23  |  2.5 KB  |  79 lines

  1. Newsgroups: comp.lang.pop
  2. Path: sparky!uunet!think.com!spool.mu.edu!agate!doc.ic.ac.uk!syma!ianr
  3. From: ianr@syma.sussex.ac.uk (Ian Rogers)
  4. Subject: Free-listing closures
  5. Message-ID: <1992Nov23.124451.14601@syma.sussex.ac.uk>
  6. Keywords: efficiency vs elegance
  7. Organization: University of Sussex at Brighton
  8. References: <TMR.92Nov21122734@emotsun.bham.ac.uk> <1992Nov22.131443.11011@syma.sussex.ac.uk> <By556G.CoB@cs.bham.ac.uk>
  9. Date: Mon, 23 Nov 1992 12:44:51 GMT
  10. Lines: 67
  11.  
  12.  
  13. Luc,
  14.  
  15. I just realised I was making a dreadful assumption in my
  16. closure freelisting stuff. Namely:
  17.  
  18.     If you're making a closure of procedure that you've closed
  19.     before, then you'll also be closing the same number of
  20.     arguments as before.
  21.  
  22. This is wrong of course. A closure should only be free-listed with
  23. repect to the number of closed arguments. I didn't know it was
  24. possible to find out that information, but dredging through the
  25. documentation reveals that -datalength- will do the trick:
  26.  
  27.     datalength(identfn(% 1, 2 %)) =>
  28.     ** 2
  29.  
  30. So a rewrite of my code is
  31.  
  32.     define lconstant pdr_table =
  33.         newproperty([], 8, [], "tmpboth")
  34.     enddefine;
  35.  
  36.     define make_closure(n) -> clos;
  37.         lvars   n, i, args, free, clos, pdr,
  38.             ;
  39.         conslist(n) -> args;    ;;; get the rest of the stuff
  40.         () -> pdr;              ;;; from the stack
  41.         pdr_table(n) -> free;   ;;; index the table with the number
  42.                                 ;;; of frozvals
  43.         if free == [] then
  44.             ;;; just like before
  45.             partapply(pdr, args) -> clos;
  46.         else
  47.             destpair(free) -> pdr_table(n) -> clos;
  48.             1 -> n;
  49.             for i in args do
  50.                 i -> frozval(n, clos);
  51.                 n + 1 -> n;
  52.             endfor;
  53.             pdr -> pdpart(clos);    ;;; need to assign the new base
  54.                                     ;;; procedure to the closure
  55.         endif;
  56.         sys_grbg_list(args);
  57.     enddefine;
  58.  
  59.     define free_closure(clos);
  60.         lvars   clos, n = datalength(clos),
  61.             ;
  62.         clos :: pdr_table(n) -> pdr_table(n);
  63.     enddefine;
  64.  
  65.  
  66. Some extra code will be needed if the closures have updaters.
  67.  
  68. axs@cs.bham.ac.uk (Aaron Sloman) writes:
  69. > for Poplog V13.6)). Steve Knight has been arguing for ages that the
  70. > mechanism should be generalised, and he is right. On the other hand
  71. > you are right that users *can* do it themselves to reduce garbage
  72. > collections, if they know enough. (Sometimes I think that if they
  73. > need to be told how to do it then they don't know enough to do it
  74. > safely!!!)
  75.  
  76. Ok guv, it's a fair cop :)
  77.  
  78. Ian.
  79.