?, ?? , quit, restart, Ctrl-C .

# Running Yacas

This section describes the special commands for the Yacas interactive sessions (for example, to restart or to exit the interpreter). These commands are not functions but special directives that only apply while running Yacas interactively. They should not be used in scripts.

?, ?? | get online help
quit, restart, Ctrl-C | basic session control

##

Interactive session commands

###

?, ?? -- get online help

##### Internal function

##### Calling format:

    ?function
    ??

##### Parameters:

`function` -- name of function or keyword to request help on

##### Description:

The directive `?` is used to request online help while running an interactive session. A name of a function or a help keyword can be specified. The corresponding reference manual section will be shown. (There is a special glossary section that contains keywords and explains some of the Yacas terminology.)

Function names should be given without quotes. Note that function names are case-sensitive in Yacas but the `?` facility will also respond to all lowercase names.

The directive `??` displays the index to all documentation.

Documentation is displayed in a Web browser of your choice. The default choice is `lynx`. An alternative browser can be set using the `SetHelpBrowser` function.

##### Examples:

Get help on a function:

    In> ?Random

The function name can be given in all lowercase:

    In> ?makefunctionplugin

Get help on a keyword:

    In> ?arity

Browse all documentation:

    In> ??

##### See also:

Help , SetHelpBrowser .

###

quit, restart, Ctrl-C -- basic session control

##### Internal function

##### Calling format:

    quit
    restart

##### Description:

Type `quit` or `restart` at the Yacas prompt to exit or to restart the interpreter.

The directives `quit` and `restart` are not reserved words or variable names. They take effect only when typed as first characters at a prompt.

Pressing `Ctrl-C` will stop the currently running calculation. If there is no currently running calculation, `Ctrl-C` will quit the interpreter.

When the interpreter quits, it saves the command history (so quitting by `Ctrl-C` does not mean a "crash").

##### Examples:

To be effective, the directive must be typed immediately after the prompt:

    In> quit
    Quitting...

We can use variables named `quit`:

    In> 1+quit
    Out> quit+1;

There is no effect if we type some spaces first:

    In>       restart
    Out> restart;

##### See also:

Exit .

##

Command-line options

The default operation of `Yacas` is to run in the interactive console mode. `Yacas` accepts several options that modify its operation. Here is a summary of options:

- filename ... (read and execute a file or several files)
- `-c` (omit line prompts)
- `-d` (print default directory)
- `-v` (print version information)
- `-f` (execute standard input as one statement)
- `-p` (do not use terminal capabilities)
- `-t` (enable extra history features)
- `--archive` filename (use a given library archive file)
- `--dlldir` directory (specify default directory for plugins)
- `--init` filename (use a given initial file)
- `--patchload` (use `PatchLoad` to load files)
- `--read-eval-print` expression (call this expression for the read-eval-print loop)
- `--rootdir` directory (specify default directory for scripts)
- `--server` port (start `Yacas` as a network server on given port)
- `--verbose-debug` (turn on showing some additional debugging information on screen)
- `--disable-compiled-plugins` (disable loading of compiled plugins, loading the script versions instead)
- `--stacksize` size (change size of stack arguments are stored on)
- `--execute` expression (run expression from the command line)

Options can be combined, for example

    yacas -pc filename

will read and execute the file `filename` non-interactively without using terminal capabilities and without printing prompts.

Here is a more detailed description of the command-line options.

    yacas -c

Inhibit printing of prompts `In>` and `Out>`. Useful for non-interactive sessions.

    yacas -f

Reads standard input as one file, but executes only the first statement in it. (You may want to use a statement block to have several statements executed.)

    yacas -p

Does not use terminal capabilities, no fancy editing on the command line and no escape sequences printed. Useful for non-interactive sessions.

    yacas -t

Enable some extra history recall functionality in console mode: after executing a command from the history list, the next unmodified command from the history list will be automatically entered on the command line.

    yacas [options] {filename}

Reads and executes commands in the filename and exits. Equivalent to `Load()`.

    yacas -v

Prints version information and exits. (This is the same information as returned by `Version()`.)

    yacas -d

Prints the path to the `Yacas` default library directory (this information is compiled into the `Yacas` executable) and exits.

    yacas --patchload

Will load every file on the command line with the `PatchLoad` command instead of the normal `Load` command, This is useful for generating HTML pages for a web site using the `Yacas` scripting language, much like you can do with the PHP scripting language.

    yacas --init [file]

Tells the system to load `file` as the initialization file. By default it loads the file `yacasinit.ys` from the scripts directory. Thus for customization one has two options: write a `~/.yacasrc` file with initialization code (as it is loaded after the initialization script is loaded), or write a custom initialization script that first uses `yacasinit.ys` and adds some extra custom code.

    yacas --read-eval-print [expression]

Call `expression` for the read-eval-print loop. The default read-eval-print loop is implemented in the initialization script `yacasinit.ys` as the function `REP`. The default behavior is therefore equivalent to `--read-eval-print` `REP()`.

There is also a fallback read-eval-print loop in the kernel; it can be invoked by passing an empty string to this command line option, as `--read-eval-print ""`.

An alternative way to replace the default read-eval-print loop is to write a custom initialization script that implements the read-eval-print loop function `REP()` instead of `yacasinit.ys`.

Care has to be taken with this option because a Yacas session may become unusable if the read-eval-print expression doesn't function correctly.

    yacas --server <port>

On some platforms server mode can be enabled at build time by passing the flag `--enable-server` to the `./configure` script. `Yacas` then allows you to pass the flag `--server` with a port number behind it, and the `Yacas` executable will listen to the socket behind that port instead of waiting for user input on the console.

Commands can be sent to the server by sending a text line as one block of data, and the server will respond back with another text block.

One can test this function by using `telnet`. First, set up the server by calling

    yacas --server 9734

and then invoke `telnet` in another window, for example:

    telnet 127.0.0.1 9734

Then type a line of Yacas input and hit Enter. The result will be one line that you will get back from the Yacas server.

Some security measures and resource management measures have been taken. No more than 10 connections can be alive at any time, a calculation cannot take more than 30 seconds, and `Yacas` operates in the secure mode, much like calling an expression by passing it as an argument to the `Secure` function. This means that no system calls are allowed, and no writing to local files, amongst other things. Something that has not been taken care of yet is memory use. A calculation could take up all memory, but not for longer than 30 seconds.

The server is single-threaded, but has persistent sessions for at most 10 users at a time, from which it can service requests in a sequenial order. To make the service multi-threaded, a solution might be to have a proxy in front of the service listening to the port, redirecting it to different processes which get started up for users (this has not been tried yet).

    yacas --rootdir [directory]

Tells the system where to find the library scripts. Here, `directory` is a path that is passed to `DefaultDirectory`. It is also possible to give a list of directories, separated by a colon, e.g. `yacas --rootdir scripts/:morescripts/`. Note that it is not necessary to append a trailing slash to the directory names.

    yacas --dlldir [directory]

Tells the system where to find the plugins. Here `directory` is a path that is passed to `DllDirectory`. It is also possible to give a list of directories separated by a colon. The default value is specified at compile time, usually `/usr/local/lib/yacas`.

    yacas --archive [file]

Use a compressed archive instead of the script library.

`Yacas` has an experimental system where files can be compressed into one file, and accessed through this command line option. The advantages are:

- Smaller disk/memory use (useful if `Yacas` is used on small hand-held computers).
- No problems with directory path separators: "`path`/`file`" will always resolve to the right file, no matter what platform (read: Windows) it runs on.
- The start-up time of the program might improve a little, since a smaller file is loaded from disk (disk access being slow), and then decompressed in memory, which might be a lot faster than loading from disk.

An additional savings is due to the fact that the script files are stripped from white spaces and comments, making them smaller and faster loading.

To prepare the compressed library archive, run `./configure` with the command line option `--enable-archive`.

The result should be the archive file `scripts.dat`. Then launch `Yacas` with the command line option `--archive scripts.dat`, with the file `scripts.dat` in the current directory.

The reason that the `scripts.dat` file is not built automatically is that it is not tested, at this time, that the build process works on all platforms. (Right now it works on Unix, MacOSX, and Win32.)

Alternatively, configure Yacas with

    ./configure --enable-archive

and the archive file `scripts.dat` will be created in the `ramscripts/` subdirectory.

When an archive is present, Yacas will try to load it before it looks for scripts from the library directories. Typing

    make archivetest -f makefile.compressor

in the `ramscripts/` directory runs all the test scripts using the archived files.

The currently supported compression schemes are uncompressed and compressed with `minilzo`. Script file stripping (removing whitespace and comments) may be disabled by editing `compressor.cpp` (variable `strip_script`).

    yacas --disable-compiled-plugins

Disable loading of compiled scripts, in favor of scripts themselves. This is useful when developing the scripts that need to be compiled in the end, or when the scripts have not been compiled yet.

    yacas --stacksize <size>

Yacas maintains an internal stack for arguments. For nested function calls, all arguments currently used are on this stack. The size of this stack is 50000 be default.

For a function that would take 4 arguments and has one return value, there would be 5 places reserved on this stack, and the function could call itself recursively 10000 steps deep.

This differs from the MaxEvalDepth mechanism. The MaxEvalDepth mechanism allows one to specify the number of separate stack frames (number of calls, nested), instead of the number of arguments pushed on the stack. MaxEvalDepth was introduced to protect the normal `C++` stack.

    yacas --execute <expression>

This instructs Yacas to run a certain expression, passed in over the command line, before dropping to the read-eval-print loop. This can be used to load a file before dropping to the command line without exiting (if there are files to run specified on the command line, Yacas will exit after running these scripts). Alternatively, the expression can exit the interpreter immediately by calling `Exit();`. When used in combination with `-pc`, the Yacas interpreter can be used to calculate something and print the result to standard output. Example:

    user% ./yacas -pc --execute '[Echo("answer ",D(x)Sin(x));Exit();]'
    answer Cos(x)
    user%