home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / 2075 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.7 KB

  1. Path: sparky!uunet!stanford.edu!snorkelwacker.mit.edu!ai-lab!life!jba
  2. From: jba@ai.mit.edu (Jonathan Amsterdam)
  3. Newsgroups: comp.lang.lisp
  4. Subject: dynamic-extent control transfers
  5. Message-ID: <JBA.92Jul22143439@kix.ai.mit.edu>
  6. Date: 22 Jul 92 18:34:39 GMT
  7. Sender: news@ai.mit.edu
  8. Distribution: comp
  9. Organization: MIT Artificial Intelligence Laboratory
  10. Lines: 38
  11.  
  12. I've been thinking about a Common Lisp feature recently, and I haven't been
  13. able to figure out how to implement it well.  That is the ability to
  14. transfer control to a point that is lexically apparent but may be elsewhere
  15. on the stack.  E.g.
  16.  
  17.     (block b
  18.             (mapc #'(lambda (x) (if (match x winner) (return-from b x)))
  19.           list))
  20.  
  21. I don't have any problem with figuring out how to get this to work
  22. correctly; my problem is how to trap the misuses, like:
  23.      
  24.     (block b
  25.        #'(lambda () (return-from b 1)))
  26.  
  27. followed by a call of the closure.  Lucid, at least, correctly catches this
  28. bug.  I can think of two implementations for doing so, neither of which I'm
  29. fond of: 
  30.  
  31. 1. Scan closures when placing them out of scope and invalidate their
  32.    control transfers.
  33.  
  34. 2. Associate a unique tag with each block and invalidate the tag on return
  35.    from the block.
  36.  
  37. (1) is expensive.  (2) is cheap but requires consing, which seems counter
  38. to the whole point of giving control transfers dynamic extent.  (The unique
  39. tag could start out being a fixnum, eliminating consing for the first
  40. couple of billion occurrences, but eventually you'd have to either cons
  41. bignums or wrap around, risking tag duplication.)
  42.  
  43. Is there any method I'm missing, something that's both cheap and cons-free?
  44. What do most implementations do?
  45.  
  46.     Jonathan Amsterdam
  47.  
  48.  
  49.  
  50.