home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!snorkelwacker.mit.edu!ai-lab!life!jba
- From: jba@ai.mit.edu (Jonathan Amsterdam)
- Newsgroups: comp.lang.lisp
- Subject: dynamic-extent control transfers
- Message-ID: <JBA.92Jul22143439@kix.ai.mit.edu>
- Date: 22 Jul 92 18:34:39 GMT
- Sender: news@ai.mit.edu
- Distribution: comp
- Organization: MIT Artificial Intelligence Laboratory
- Lines: 38
-
- I've been thinking about a Common Lisp feature recently, and I haven't been
- able to figure out how to implement it well. That is the ability to
- transfer control to a point that is lexically apparent but may be elsewhere
- on the stack. E.g.
-
- (block b
- (mapc #'(lambda (x) (if (match x winner) (return-from b x)))
- list))
-
- I don't have any problem with figuring out how to get this to work
- correctly; my problem is how to trap the misuses, like:
-
- (block b
- #'(lambda () (return-from b 1)))
-
- followed by a call of the closure. Lucid, at least, correctly catches this
- bug. I can think of two implementations for doing so, neither of which I'm
- fond of:
-
- 1. Scan closures when placing them out of scope and invalidate their
- control transfers.
-
- 2. Associate a unique tag with each block and invalidate the tag on return
- from the block.
-
- (1) is expensive. (2) is cheap but requires consing, which seems counter
- to the whole point of giving control transfers dynamic extent. (The unique
- tag could start out being a fixnum, eliminating consing for the first
- couple of billion occurrences, but eventually you'd have to either cons
- bignums or wrap around, risking tag duplication.)
-
- Is there any method I'm missing, something that's both cheap and cons-free?
- What do most implementations do?
-
- Jonathan Amsterdam
-
-
-
-