Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!math.fu-berlin.de!opal!net From: net@opal.cs.tu-berlin.de (Oliver Laumann) Newsgroups: comp.lang.scheme Subject: `return' in Scheme (was: C->Scheme mappings) Message-ID: <3535@kraftbus.cs.tu-berlin.de> Date: 31 May 91 09:26:56 GMT References: <1991May28.191834.15025@apd.mentorg.com> <9105302308.AA18221@cymbal.reasoning.com.> Organization: Technical University of Berlin, Germany Lines: 39 In article <9105302308.AA18221@cymbal.reasoning.com.> Gyro@reasoning.com writes: > I'm trying to map the various C control statements into > Scheme. The translation of break, continue, and return > are giving me trouble. [..] > > I suspect I need to do something with call-with-current-continuation > > 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; e.g. I suppose what the original poster wanted is to be able to write (return expression) in the middle of a function body to terminate the function and return the value of an expression. If Scheme had macros, this could be implemented easily by defining a new version of `define' that wraps a call/cc around the body of the function: (define-macro (improved-define head . body) `(define ,head (call-with-current-continuation (lambda (return) ,@body)))) `improved-define' could then be used like this: (improved-define (redraw window) (if (invisible? window) (return #f)) ;; do something complex... ) -- Oliver Laumann net@tub.cs.tu-berlin.de net@tub.UUCP ol@gnu.ai.mit.edu