Hello,
I need to develop a ffi and I read The Racket Foreign Interface. Now I’m trying to understand how to install the correct libraries for each supported operating systems and I’m reading the Raco setup documentation.
There’s a thing I don’t understand:
The underlined code is and/c or or/c?
Matteo
It’s and/c
.
The function relative-path?
itself has the contract (or/c path? string? path-for-some-system?) -> boolean?
. Because of this, an expression like (relative-path? 1)
results in an error, not false. So relative-path?
alone cannot be used as a contract that works on all values.
The workaround here is to use and/c
to short-circuit (in the same way that and
does).
- If the input to
(and/c path-string? relative-path?)
is a path-string?
, then relative-path?
is used for the contract behavior.
- If the input to
(and/c path-string? relative-path?)
is not a path-string?
, then relative-path?
is not used at all. The whole contract short-circuits and doesn’t satisfy the input.
2 Likes
Thank you, very interesting.