Erroring on exact ints outside the range 0-255 works for me when SRFI 170 is available.

BTW, the reason that R7RS-small `exit` accepts an arbitrary object is that Plan 9 exit values are strings; the empty string indicates normal termination.  The kernel decorates the string with the program's name and pid and then passes it to Plan 9's wait.

On Wed, Aug 14, 2019 at 4:50 PM Lassi Kortela <> wrote:
> I think we should say that when an R7RS system implements
> SRFI 170, the R7RS exit and emergency-exit procedures must interpret an
> exact integer argument modulo 255 as a Posix exit argument.

Agreed, but not sure about the modulo 255 part. That's just uncivilized
:p A Lisp is not supposed to implicitly mod people's integers.

Here's the Windows situation:

* ExitProcess function

* GetExitCodeProcess function

They use UINT / DWORD which is 32 bits (or 32/64?). The docs don't say
anything about modulo of clamping. But apparently 259 is an unambiguous
exit code. So even on Windows, values outside 0..255 are hazardous.

Also, if Wine is emulating a Windows program on Unix, one might expect
the exit code of the Windows program to be truncated to fit the Unix

More trouble comes from the fact that the Posix waitid() extension
allows people to actually utilize the bits of an int beyond the first 8.
Though any programmer who does so is probably asking for trouble. What
about portability to other systems that lop off the extra bits, or
porting 64-bit ints to 32-bit ints? I don't mind if Scheme doesn't
support any of this stuff.

Gambit's stance of erroring on anything outside 0..255 is starting to
look like the least objectionable compromise. We could mod the exit
values like Unix, but that's not intuitive to anyone except Unix
diehards. 256 aliasing to a successful exit (0) is particularly worrisome.