hal88
hal88

Reputation: 131

How to terminate a scheme program early? (Is there an "exit"?)

I would like something like:

(cond ((< x 3) (and (display "Error Message") (exit)))

(else (foo y))

In other words I'd like to display a message and terminate when a condition is met. How can I do this? Is there such an exit function?

Thanks in advance!

Upvotes: 6

Views: 5433

Answers (3)

Stephane Rolland
Stephane Rolland

Reputation: 39916

On ChezScheme I type:

(exit)

It took me much less longer than exiting vim the first time.

Upvotes: 3

C. K. Young
C. K. Young

Reputation: 223133

SRFI 23 provides error. For error conditions, doing that is much better than calling exit, because it makes it possible for other code to catch the error and do error-handling. (Some implementations implement exit as an exception anyway, but that doesn't take away from my point that using error is more appropriate.)

SRFI 34 provides a more complete exception facility, and can be even more appropriate than error.

Upvotes: 7

user448810
user448810

Reputation: 17866

R5RS Scheme, and prior versions, does not require an exit function, though most implementations provide one. R6RS Scheme does require an exit function. Even without an exit function, it is generally possible to arrange the control flow of your program so that it just "falls off the end" when it is finished. If you need an exit and your implementation doesn't provide one, you can build your own with call/cc.

Upvotes: 4

Related Questions