Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

exit

scheme

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!

like image 275
hal88 Avatar asked Oct 15 '11 22:10

hal88


3 Answers

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.

like image 57
Chris Jester-Young Avatar answered Sep 27 '22 21:09

Chris Jester-Young


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.

like image 45
user448810 Avatar answered Sep 27 '22 21:09

user448810


On ChezScheme I type:

(exit)

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

like image 31
Stephane Rolland Avatar answered Sep 27 '22 22:09

Stephane Rolland