exit(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’… exit(3scm)

okay so real quick β€” this page lives in the Scheme Programmer's Manual, and it's genuinely the most main-character procedure ever because it's the one that ends the whole show. no encore, no curtain call, just ✨gone✨.


πŸŽ€ NAME

exit β€” exit the program. that's it. that's the whole vibe. bye bestie πŸ’–


πŸ“š LIBRARY

import it however your Scheme likes, all three paths lead to the same slay:

(import (rnrs))                     ;R6RS
(import (rnrs programs))            ;R6RS
(import (scheme process-context))   ;R7RS

✨ SYNOPSIS

(exit)
(exit obj)

🌸 DESCRIPTION

so what it does: it exits the running program and tells the operating system an exit value. like, it communicates. it reports back. very communicative of it honestly 🫢.

if you don't hand it an argument, exit should tell the OS that the program exited normally. (good ending 🌈). if you do pass an argument, exit should translate that argument into an appropriate exit value for the operating system β€” it figures out how to say what you meant in OS-speak.

here's the lil gotcha πŸ‘€: if obj is #f, the exit is assumed to be abnormal. not the good ending. the messy ending πŸ’€.

  • R7RS β€” runs all outstanding dynamic-wind after procedures, terminates the running program, and communicates an exit value to the operating system. and in R7RS, (exit #t) is literally the same thing as (exit). same energy, same result ✨.
the exit procedure must not signal an exception or return to its continuation. like, ever. that's non-negotiable. and because it's got that whole "run the handlers first" requirement, it is not just the operating system's exit procedure β€” it's got extra responsibilities, it's doing the most, and it's doing it for you πŸ’….

πŸ› οΈ IMPLEMENTATION NOTES

most implementations just return obj immediately to the operating system if it's a number between 0 and 255. no notes, straightforward, iconic.

  • GNU Guile, Chez Scheme β€” these implementations run the dynamic-wind after procedures. good for them honestly πŸ‘‘.

🚫 RETURN VALUES

this procedure does not return.

like. at all. it's not coming back. don't wait up 😭.


πŸ’« EXAMPLES

(exit)     ;no return

see that comment? ;no return. it wasn't kidding.


🧚 APPLICATION USAGE

ngl, this procedure should be avoided in libraries. like, not your place, bestie πŸ™ˆ. applications mainly use it to return errors to the operating system β€” either signalling to the shell that the command has failed to execute correctly, or signalling to the init system that the service has failed. drama, but make it diagnostic πŸ’€.


πŸ’œ COMPATIBILITY

R6RS does not explicitly say that the dynamic-wind exit handlers should run. some implementations run them and some do not. so like... it's giving "it depends" and honestly that's just how it is πŸ¦‹.


πŸ’₯ ERRORS

this procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed. you gave it too much or not enough. it noticed. 😀
  • R7RS β€” the assertions described above are errors. implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. yes, catastrophically. that's the actual word. no cap πŸ’€πŸ”₯.

πŸ‘€ SEE ALSO

  • emergency-exit(3scm)
  • exit(3)
  • dynamic-wind(3scm)

⭐ STANDARDS

R6RS, R7RS πŸŽ€


πŸ¦‹ HISTORY

this procedure first appeared in R6RS and later appeared in R7RS as well. and fun fact: MacLISP had a quit function with similar functionality. so this vibe is, like, historically certified πŸ“œβœ¨.


🫢 AUTHORS

this page is part of the scheme-manpages project. it includes materials from the RnRS documents. more information can be found at https://github.com/schemedoc/manpages/.


okay that's the whole page!! and yeah, dated 2022-03-26, straight out of the Scheme Programmer's Manual β€” exit(3scm), our forever icon, taken from the manpage source and living rent free in your terminal πŸ’–πŸŒ·βœ¨

πŸ“¦ where this page comes from