20. Libraries
How to make a library of functions that you can use in other files.
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.
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")
Provide
The provide
command makes functions available for other files to use.
One way to use it is to list all of the functions you want to allow
other files to use:
(provide posn-add posn-sub posn-scale posn-distance)
Sometimes you just want to make every function in the file available. There is a shortcut to do that:
(provide (all-defined-out))
Last modified August 24, 2021: intermediate cs and initial hugo changeover (1784229)