Topfind

Name

Topfind -- [Module to load packages into toploops]

SIGNATURE

module Topfind :
  sig
    val predicates : string list ref
    val add_predicates : string list -> unit
    val syntax : string -> unit
    val standard_syntax : unit -> unit
    val revised_syntax : unit -> unit
    val don't_load : string list -> unit
    val don't_load_deeply : string list -> unit
    val load : string list -> unit
    val load_deeply : string list -> unit
    val reset : unit -> unit
  end

DIRECTIVES

#require "package-name-list";;
#camlp4o ;;
#camlp4r ;;
#list ;;

PACKAGING

The Topfind module is part of the "findlib" package. The module depends on the presence of a toploop. When building a toploop, it is automatically linked in if "findlib" is linked in, e.g.

ocamlfind ocamlmktop options -package findlib -linkpkg options

When the platform supports DLLs, another possibility to get a toploop with findlib directives is to load the file "topfind" (normally installed in the standard library directory):

~ > ocaml
        Objective Caml version 3.04

# #use "topfind";;
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  Topfind.reset();;         to force that packages will be reloaded

- : unit = ()
# _

This works even in scripts (but the startup message is suppressed in this case).

The module is not thread-safe; if used in a multi-threaded script, all packgage loading must have happened before the first thread forks.

DESCRIPTION

The Topfind module contains some functions simplifying package loading in scripts. Most important, there is a new directive "#require" for the same purpose.

The Topfind module needs some initialization, in particular the predicates variable needs to be set, and the packages already compiled into the toploop needs to be declared by the don't_load function. If the toploop has been built by ocamlfind[Command-line interface of the Package manager], the necessary initialization is automatically compiled in.

The variable Topfind.predicates

val predicates : string list ref

The variable contains the set of predicates that is assumed when packages are loaded.

Topfind.add_predicates predlist

val add_predicates : string list -> unit

This function adds the passed predicates predlist to the variable predicates.

Topfind.syntax variant

val syntax : string -> unit

This function emulates the -syntax command line switch of ocamlfind.

Topfind.standard_syntax ()

val standard_syntax : unit -> unit

The same as syntax "camlp4o".

Topfind.revised_syntax ()

val revised_syntax : unit -> unit

The same as syntax "camlp4r".

Topfind.don't_load pkglist

val don't_load : string list -> unit

Declares the packages enumerated in pkglist as being linked into the toploop.

Topfind.don't_load_deeply pkglist

val don't_load_deeply : string list -> unit

Declares the packages enumerated in pkglist and all direct and indirect ancestors as being linked into the toploop.

Topfind.load pkglist

val load : string list -> unit

The packages enumerated in pkglist are loaded in turn; packages that have already been loaded or that have been declared as linked in are skipped.

Topfind.load_deeply pkglist

val load_deeply : string list -> unit

The packages enumerated in pkglist and all direct or indirect ancestors are loaded in topological order; packages that have already been loaded or that have been declared as linked in are skipped.

Topfind.reset ()

val reset : unit -> unit

This function causes that Topfind forgets that any package has already been loaded. Infomation about packages linked into the toploop remain intact. The effect of this function is that all dynamically loaded packages will be loaded again when load, load_deeply functions, or the #require directive are executed.

#require "package-name-list";;

#require "package-name-list";;

The argument of the directive is a list of package names, separated by commas and/or whitespace. The directive has the same effect as load_deeply, i.e. the listed packages and all direct or indirect ancestors are loaded in topological order; packages that have already been loaded or that have been declared as linked in are skipped.

#camlp4o ;;

#camlp4o ;;

Selects the standard syntax and loads the camlp4 preprocessor.

#camlp4r ;;

#camlp4r ;;

Selects the revised syntax and loads the camlp4 preprocessor.

#list ;;

#list ;;

Lists the packages that are in the search path.