When might `(find-lib-dir)` return `#f`?

Functions like find-lib-dir from setup/dirs document that:

The result is #f if no such directory is available.

What does "available" mean in this context? From experiments, it seems that the functions don't return #f merely because the relevant directory does not exist. Are all such functions like find-collects-dir in that "a #f result is likely only in a stand-alone executable that is distributed without libraries"?

I have some code for Guix to generate config.rktd tables for layers that extend some parent layer. Right now, the code runs in an arbitrary Racket and just manipulates the hash tables, which involves some hard-coded assumptions about how a layer is laid out. It seems like it might be better to run the code in the parent layer and use the setup/dirs functions, but I'm not sure if I need to be prepared to handle #f results.

1 Like

Yes, with the current implementation, find-lib-dir can produce #f only if find-collects-dir produces #f. That is generally true of directories where the default is derived from the collection-directory path.

A stand-alone executable disables the collection path with the same mechanism as providing -X "" as command-line arguments to racket. It's fairly difficult to load anything after -X "" — unless some libraries are predefined, as in a stand-alone executable.

For your context, I don't think you need to plan for the case that find-lib-dir returns #f.