20. Libraries
Use require and provide to make functions from one file available
in another file.
Require and provide
Require loads functions from another file. Provide makes functions available for other files to load.
Provide
The provide command makes functions available for other files to
use. You put it into the file with the functions you want to make
available.
If you just want to make every function in the file available, there is a shortcut to do that:
(provide (all-defined-out))
Sometimes you want to only make some of your functions available. Normally you would not want to provide your helper functions, for example.
(provide posn-add posn-sub posn-scale posn-distance)
Require
In order to use the functions in another file, you need to require that file.
You already know (require picturing-programs) but when we use require
we need to give the whole filename.
(require "posn-util.rkt")
Checklist to make this work:
- The
posn-utilfile has aprovidestatement inside it. - The file with the
requireis saved and in the same folder as theposn-utilfile.