Using Ciao from the command line

Author(s): Manuel Hermenegildo.

Starting/exiting the top-level shell

The basic methods for starting/exiting the top-level shell have been discussed before. If upon typing ciao you get a ``command not found'' error or you get a longer message from Ciao before starting, it means that either Ciao was not installed correctly or you environment variables are not set up properly. Follow the instructions on the message printed by Ciao or refer to the installation instructions regarding user-setup for details.

Getting help

The basic methods for accessing the manual on-line have also been discussed before. Use the table of contents and the indices of predicates, libraries, concepts, etc. to find what you are looking for. Context-sensitive help is available within the emacs environment (see below).

Compiling and running programs

Once the shell is started, you can compile and execute modules inside the interactive top-level shell in the standard way. E.g., type use_module(file)., use_module(library(file)). for library modules, ensure_loaded(file). for files which are not modules, and use_package(file). for library packages (these are syntactic/semantic packages that extend the Ciao language in many different ways). Note that the use of compile/1 and consult/1 is discouraged in Ciao.

For example, you may want to type use_package(iso_strict) to ensure Ciao has loaded all the ISO builtins (whether this is done by default or not depends on your .ciaorc file). Do not worry about any ``module already in executable'' messages --these are normal and simply mean that a certain module is already pre-loaded in the top-level shell. At this point, typing write(hello). should work.

Note that some predicates that may be built-ins in typical Prolog implementations are available through libraries in Ciao. This facilitates making small executables.

To change the working directory to, say, the examples directory from the Ciao root directory, first do:

?- use_module(library(system)).

(loading the system library makes a number of system-related predicates such as cd/1 accessible) and then:

?- cd('examples').

For more information see The interactive top-level shell.

Generating executables

Executables can be generated from the top-level shell (using make_exec/2) or using the standalone compiler (ciaoc). To be able to make an executable, the file should define the predicate main/1 (or main/0), which will be called upon startup (see the corresponding manual section for details). In its simplest use, given a top-level foo.pl file for an application, the compilation process produces an executable foo, automatically detecting which other files used by foo.pl need recompilation.

For example, within the examples directory, you can type:

?- make_exec(hw,_).

which should produce an executable. Typing hw in a shell (or double-clicking on the icon from a graphical window) should execute it.

For more information see The interactive top-level shell and The standalone command-line compiler.

Running Ciao scripts

Ciao allows writing scripts. These are files containing Ciao source but which get executed without having to explicitly compile them (in the same way as, e.g., .bat files or programs in scripting languages). As an example, you can run the file hw in the examples directory of the Ciao distribution and look at the source with an editor. You can try changing the Hello world message and running the program again (no need to recompile!).

As you can see, the file should define the predicate main/1 (not main/0), which will be called upon startup. The two header lines are necessary in Unix in. In Windows you can leave them in or you can take them out, but you need to rename the script to hw.pls. Leaving the lines in has the advantage that the script will also work in Unix without any change.

For more information see The script interpreter.

The Ciao initialization file

The Ciao toplevel can be made to execute upon startup a number of commands (such as, e.g., loading certain files or setting certain Ciao flags) contained in an initialization file. This file should be called .ciaorc and placed in your home directory (e.g., ~, the same in which the .emacs file is put). You may need to set the environment variable HOME to the path of this directory for the Ciao toplevel shell to be able to locate this file on startup.