Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!apple!sun-barr!decwrl!shelby!neon!max From: max@Neon.Stanford.EDU (Max Hailperin) Newsgroups: comp.object Subject: Re: Continuations Message-ID: <1989Nov29.170929.25196@Neon.Stanford.EDU> Date: 29 Nov 89 17:09:29 GMT References: <1989Nov28.224937.4183@mentor.com> Sender: USENET News System Reply-To: max@Neon.Stanford.EDU (Max Hailperin) Organization: Computer Science Department, Stanford University Lines: 45 In article <1989Nov28.224937.4183@mentor.com> plogan@mentor.com (Patrick Logan) writes: > ... >My example of an object that uses continuations is a discrete event >simulator. > ... This is a superb example, but stops one step short of showing the real power of the idea. If all you are simulating is simple things like and gates, you can just code the simulator the way Abelson and Sussman do in their book, something like (simulator 'after-delay 2 (lambda () (self 'set-output-pin! (and input-pin-one input-pin-two)))) instead of (simulator 'wait-for 2) (self 'set-output-pin! (and input-pin-one input-pin-two)) The win in doing it the latter way (where simulator's wait-for uses call-with-current-continuation) comes if you are simulating something higher level. For example, I've been involved in some multiprocessor simulations where you want to just treat the processing elements as black boxes and simulate them by directly running the application code on the real machine that's doing the simulating, time how long it takes, and apply some scaling factor. *However*, whenever a remote reference happens, you want to trap back to the simulator, which will cause the right sequence of events to happen to simulate the network traffic, etc. Meanwhile, other processors may be doing their thing. Eventually, the event happens that corresponds to the memory contents from the remote reference arriving back at the processor, and you wnat to pick up where you left off -- which may be arbitrarily deeply nested in procedure calling. This can trivially be done by embedding a call-with-current-continuation in the remote-reference code, but otherwise is a real nightmare. I know--I've done it both ways. The key difference between the processor and the and-gate is that the point at which you want to delay may be buried deep in calls. This can happen in other, simpler situations as well, basically any time you have a notion of "interruption" in the normal, non-trivial, behavior of an entity. The fact that this comes up all the time in simulating bussiness organizations or what-not explains why Simula had coroutining (which is what first-class continuations are being used for in this example). Brought to you by Super Global Mega Corp .com