To start, require bzlib/os:
(require (planet bzlib/os))
To require modules only within windows, use
(require/windows <require-spec> ...)
<require-spec>takes the same form as regular require statements. In Mac OS or Unix, the above statement evalutes to
To do the same for Mac OS, use
require/macosx. And use
To specify multiple platform in one statement - use
(require/os (:windows <required-spec> ...)
(:macosx <required-spec> ...)
(:unix <required-spec> ...)
(else <required-spec> ...))
:windowsto specify the window's branch inclusion. Use
:macosxfor Macs, and
:unixfor Unix. All are optional.
elseto specify non-platform specific includes. If the
elsebranch exists, it must be the last branch.
There are also os-dependent provide statements, provided to mirror the require statements (even though it's probably less likely to be used).
provide/oshas the same structure has
:unixto write OS-dependent provide branch, and use
elseto write OS independent branch. If the
elsebranch exists it must be the last branch
provide/*behaves the same as regular
providein that they can only be called at top level or module level (
provideonly works at module level).
The most general form is conditional expressions, which can be called at any position.
For windows, use
(+:windows <exp> <exp2>)evaluates to
(+:windows <exp>)evaluates to
(void)otherwise. It is equivalent to
(+:windows <exp> (void)).
For Macs, use
+:macosxin the same way as above. For Unix, use
If you need to write more than 2 OS branch, use
+:os, which is the foundation of all above macros:
(+:os (:windows exp)
provide/os, one of the branches with labels of
:unixget evaluated for the respective OS. The
elsebranch is evaluated for platform independent expression; and if it exists it must be the last expression.
It is possible to write
(+:os), which gets evaluated to
Eli has cautioned that one must make sure no .zo files are copied across platforms by using this pattern.
In general one should write platform independent code, but of course that would not be possible in all situations. It is always better to isolate the OS-specific code to their own modules, and make sure all those modules all expose the same signatures; Unit can aid with this pattern.
bazthat work specifically for windows
(require/os (:windows "bar-windows.ss") (else "bar.ss"))