A software library is a collection of procedures that can be used in programs.
Using libraries simplifies the development of new programs. When you use procedures that you already know work correctly, you reduce the amount of time you need to spend coding, the number of possible bugs your code can have, and how much of your project you need to test.
You created your even?
block using another custom block, divisible by?
. If you want to use even?
in another project one day, you must export both blocks in order for even?
to work properly.
If you ever see this red Obsolete!
block in code you have imported, it means that a required block was not exported. You'll have to go back to the original project and export again being sure to select all of the blocks needed by the blocks you want.
even?
predicate to develop an odd?
predicate for your library.You can create algorithms from scratch or by combining or modifying existing algorithms. When you are thinking of using existing code, you can either use your own code or use code from someone else's library.
keep
), and use it to answer these questions:
divisors
block using keep
.divisors
block
for
or for each
, but it will require less code to build it with . (You learned about keep
on Unit 2 Lab 3 Page 5: Keep
ing Items from a List.)mod
, but you already built (using mod
), so divisible by?
will be simpler to use.number of divisors
block.keep
to answer each of these questions that were introduced above:
You've now made a small library, and you might want to write a list of instructions for how to use the functions in your library (for example, divisors of
takes a positive integer as input and reports a list of numbers). The instructions form an Application Program Interface for the library.
An application program interface (API) documents what a programmer needs to know about using a library: it's a description of each procedure's purpose, inputs, and outputs (but not its algorithms).
A common kind of API is a web API in which the library exists on someone else's computer. For example, the Google Maps API describes how to embed a Google Map on your own website.
A web API is just a call to a procedure on another machine. For example, these are three different notations for the same procedure call, which looks up the number of searches for "BJC" in the US:
EXPLORE (q = BJC, geo = US)