Carp/docs/Libraries.md

4.5 KiB

Working with libraries and modules

Below is a list of 'core' modules that comes included with the Carp compiler. Modules marked with the symbol '⦁' are imported by default, other modules must be imported by loading their file. For example, to get access to the Bench module, do the following:

(load "Bench.carp")

Using the functions in the Bench module still requires pre-pending them with the module name, i.e. (Bench.bench fib). To avoid that, also do (use Bench).

To see what functions a certain module contains, use the info command:

(info Bench)

External librares can be loaded by using their relative or absolute location in your file system as the path. To make a library publically available in a more general way you can add it to your Carp project's search path:s (found by running :p in the repl). For instance, here's how you would add the NCurses library so that it can be loaded with just (load "NCurses.carp").

(Project.config "search-path" "~/Projects/carp-ncurses")

This line of configuration can be put into a ~/.carp/profile.carp file to make it apply in all your projects.

Loading via git

You can also load libraries via Git like that:

(load "git@github.com:hellerve/anima.carp@master")

This will download the Anima library to ~/.carp/libs/<library>/<tag> and load the file anima.carp in it. To get a stable version of the library you should specify a git tag rather than @master.

If you want to make a library ready for loading, either prepare a file that has the same name as the library—in the case above, anima.carp—or a file called main.carp as an entrypoint.

Please note that for private repos only loading through SSH is supported. For public repos you can use HTTPS:

(load "https://github.com/hellerve/anima@master")

Core Modules

Basics

Numerics

Text

Collections

System

Development

Graphics, sound and interaction

External Libraries

For a growing list of Carp packages, see Carpentry.