Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cis.ohio-state.edu!ucbvax!bloom-beacon!dont-send-mail-to-path-lines From: gyro@cymbal.reasoning.COM (Scott Layson Burson) Newsgroups: comp.lang.scheme Subject: C->Scheme mappings Message-ID: <9106020028.AA07159@cymbal.reasoning.com.> Date: 2 Jun 91 00:28:30 GMT References: <1991May31.093235.25653@news.cs.indiana.edu> Sender: daemon@athena.mit.edu (Mr Background) Reply-To: Gyro@reasoning.com Organization: The Internet Lines: 45 Date: Fri, 31 May 91 09:32:15 EST From: Robert Hieb gyro@cymbal.reasoning.COM (Scott Layson Burson) writes: > Date: 28 May 91 19:18:34 GMT > From: "Joe Mueller @ APD x1367" > I'm trying to map the various C control statements into > Scheme. The translation of break, continue, and return > are giving me trouble. >You don't need call-with-current-continuation. >`return' is implicit in Scheme: a lambda body always returns the value of its >last form. So you don't have to do anything special with it... This is true only if the "return" is in tail position with respect to the procedure body, which is not in general true in C code. Such code can often be rewritten to put all return statements in tail position, but that may not be the sort of transformation desired, and is not always reasonable. To get a fully general return mechanism "call/cc" IS required; one must wrap a call to "call/cc" around each procedure body that has an explicit return in nontail position. One can then invoke the continuation to return. It is *always* possible to transform the C program into the appropriate form. Therefore CALL/CC is *not* *required* for a "fully general" return mechanism (in the C sense). It is not until you get to setjmp/longjmp that CALL/CC becomes necessary. Whether the result is "pretty" is another question, but beauty is in the eye of the beholder. I think it is quite a worthwhile exercise for anyone to understand how control constructs from traditional languages get translated into Scheme by means of these transformations, and without use of CALL/CC. I would go so far as to say that such an understanding is a prerequisite to developing a true Scheme style. This is the spirit in which I replied to Joe Mueller's question. Yes, you can do these things with CALL/CC, but you'll miss the chance to really understand what Scheme is all about. -- Scott Gyro@Reasoning.COM