Getting started on Un*x-like machines
Author(s): Manuel Hermenegildo.
This part guides you through some very basic first steps with Ciao on a Un*x-like system. It assumes that Ciao is already installed correctly on your Un*x system. If this is not the case, then follow the instructions in Installing Ciao from the source distribution first.
We start with by describing the basics of using Ciao from a normal command shell such as sh/bash, csh/tcsh, etc. We strongly recommend reading also An introduction to the Ciao emacs environment (Un*x) for the basics on using Ciao under emacs, which is a much simpler and much more powerful way of developing Ciao programs, and has the advantage of offering an almost identical environment under Un*x and Windows.
Testing your Ciao Un*x installation
It is a good idea to start by performing some tests to check that Ciao is installed correctly on your system (these are the same tests that you are instructed to do during installation, so you can obviously skip them if you have done them already at that time). If any of these tests do not succeed either your environment variables are not set properly (see Un*x user setup for how to fix this):
- Typing ciao (or ciaosh) should start the typical Prolog-style top-level shell.
- In the top-level shell, Ciao library modules should load correctly. Type for example use_module(library(dec10_io)) --you should get back a prompt with no errors reported.
- To exit the top level shell, type halt. as usual, or ^D.
- Typing ciaoc should produce the help message from the Ciao standalone compiler.
- Typing ciao-shell should produce a message saying that no code was found. This is a Ciao application which can be used to write scripts written in Ciao, i.e., files which do not need any explicit compilation to be run.
Also, the following documentation-related actions should work:
- If the info program is installed, typing info should produce a list of manuals which should include Ciao manual(s) in a separate area (you may need to log out and back in so that your shell variables are reinitialized for this to work).
- Opening with a WWW browser (e.g., netscape) the directory or URL corresponding to the DOCDIR setting should show a series of Ciao-related manuals. Note that style sheets should be activated for correct formatting of the manual.
- Typing man ciao should produce a man page with some very basic general information on Ciao (and pointing to the on-line manuals).
- The DOCDIR directory should contain the manual also in the other formats such as postscript or pdf which specially useful for printing. See Printing manuals (Un*x) for instructions.
Un*x user setup
If the tests above have succeeded, the system is probably installed correctly and your environment variables have been set already. In that case you can skip to the next section.
Otherwise, if you have not already done so, make the following modifications in your startup scripts, so that these files are used (<LIBROOT> must be replaced with the appropriate value, i.e., where the Ciao library is installed):
- For users a csh-compatible shell (csh, tcsh, ...), add to ~/.cshrc:
if ( -e <v>libroot</v>/ciao/DOTcshrc ) then source <v>libroot</v>/ciao/DOTcshrc endif
Note: while this is recognized by the terminal shell, and therefore by the text-mode Emacs which comes with Mac OS X, the Aqua native Emacs 21 does not recognize that initialization. It is thus necessary, at this moment, to set manually the Ciao shell (ciaosh) and Ciao library location by hand. This can be done from the Ciao menu within Emacs after a Ciao file has been loaded. We believe that the reason is that Mac OS X does not actually consult the per-user initialization files on startup. It should also be possible to put the right initializations in the .emacs file using the setenv function of Emacs-lisp, as in
(setenv "CIAOLIB" "<v>libroot</v>/ciao")
The same can be done for the rest of the variables initialized in <v>libroot</v>/ciao/DOTcshrc
- For users of an sh-compatible shell (sh, bash, ...), the installer will add to ~/.bashrc the next lines:
if [ -f <v>libroot</v>/ciao/DOTprofile ]; then . <v>libroot</v>/ciao/DOTprofile fi
This will set up things so that the Ciao executables are found and you can access the Ciao system manuals using the info command. Note that, depending on your shell, you may have to log out and back in for the changes to take effect.
- Also, if you use emacs (highly recommended) the install will add the next line to your ~/.emacs file:
(load-file "<v>libroot</v>/ciao/ciao-mode-init.el") (if (file-exists-p "<v>libroot</v>/ciao/ciao-mode-init.el") (load-file "<v>libroot</v>/ciao/ciao-mode-init.el") )
If after following these steps things do not work properly, then the installation was probably not completed properly and you may want to try reinstalling the system.
Using Ciao from a Un*x command shell
Starting/exiting the top-level shell (Un*x)
The basic methods for starting/exiting the top-level shell have been discussed above. 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 (Un*x)
The basic methods for accessing the manual on-line have also been discussed above. 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 (Un*x)
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) 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 in 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').
(in Ciao the sequence $/ at the beginning of a path name is replaced by the path of the Ciao root directory).
For more information see The interactive top-level shell.
Generating executables (Un*x)
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 stand-alone command-line compiler.
Running Ciao scripts (Un*x)
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 Un*x 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 Un*x without any change.
For more information see The script interpreter.
The Ciao initialization file (Un*x)
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.
Printing manuals (Un*x)
As mentioned before, the manual is available in several formats in the reference directory within the doc directory in the Ciao distribution, including postscript or pdf, which are specially useful for printing. These files are also available in the DOCDIR directory specified during installation. Printing can be done using an application such as ghostview (freely available from http://www.cs.wisc.edu/~ghost/index.html) or acrobat reader (http://www.adobe.com, only pdf).
An introduction to the Ciao emacs environment (Un*x)
While it is easy to use Ciao with any editor of your choice, using it within the emacs editor/program development system is highly recommended: Ciao includes an emacs mode which provides a very complete application development environment which greatly simplifies many program development tasks. See Using Ciao inside GNU emacs for details on the capabilities of ciao/emacs combination.
If the (freely available) emacs editor/environment is not installed in your system, we highly recommend that you also install it at this point (there are instructions for where to find emacs and how to install it in the Ciao installation instructions). After having done this you can try for example the following things:
- A few basic things:
- Typing ^H i (or in the menus Help->Manuals->Browse Manuals with Info) should open a list of manuals in info format in which the Ciao manual(s) should appear.
- When opening a Ciao file, i.e., a file with .pl or .pls ending, using ^X^Ffilename (or using the menus) the code should appear highlighted according to syntax (e.g., comments in red), and Ciao/Prolog menus should appear in the menu bar on top of the emacs window.
- Loading the file using the Ciao/Prolog menu (or typing ^C l) should start in another emacs buffer the Ciao toplevel shell and load the file. You should now be able to switch the the toplevel shell and make queries from within emacs.
Note: when using emacs it is very convenient to swap the locations of the (normally not very useful) Caps Lock key and the (very useful in emacs) Ctrl key on the keyboard. How to do this is explained in the emacs frequently asked questions FAQs (see the emacs download instructions for their location).
(if these things do not work the system or emacs may not be installed properly).
- You can go to the location of most of the errors that may be reported during compilation by typing ^C `.
- You can also, e.g., create executables from the Ciao/Prolog menu, as well as compile individual files, or generate active modules.
- Loading a file for source-level debugging using the Ciao/Prolog menu (or typing ^C d) and then issuing a query should start the source-level debugger and move a marker on the code in a window while execution is stepped through in the window running the Ciao top level.
- You can add the lines needed in Un*x for turning any file defining main/1 into a script from the Ciao/Prolog menu or by typing ^C I S.
- You can also work with the preprocessor and auto-documenter directly from emacs: see their manuals or browse through the corresponding menus that appear when editing .pl files.
We encourage you once more to read Using Ciao inside GNU emacs to discover the many other functionalities of this environment.
Keeping up to date (Un*x)
You may want to read Beyond installation for instructions on how to sign up on the Ciao user's mailing list, receive announcements regarding new versions, download new versions, report bugs, etc.