.. _repl: ======== The REPL ======== Sprite has a read-eval-print loop for Curry expressions. It compiles each expression with the Curry front end, as :func:`curry.compile` with mode ``'expr'`` does, and evaluates it with :func:`curry.eval`. The same route serves ``sprite-exec -g`` and the text goals of the Python API, so the three agree on every goal. To start the REPL, run the module ``curry.tools.icy`` with the Python of the installation: .. code-block:: bash % install/bin/python -m curry.tools.icy Prelude> The prompt names the loaded module. The Prelude is loaded at the start. The REPL runs on the default backend of the installation, the C++ backend, with the flags of ``SPRITE_INTERPRETER_FLAGS`` (see :doc:`CommandLineInterface/EnvironmentVariables`). The REPL runs in time mode by default: the scheduler rotates its alternatives every 10 ms of wall time, so a diverging alternative beside a value costs a quantum, not a count of steps. The values of a non-deterministic expression may then come in a different order from one evaluation to the next. To pin the order, start the REPL in step mode, where the schedule depends on the expression alone: .. code-block:: bash % SPRITE_ROTATION=steps:65536 install/bin/python -m curry.tools.icy The REPL has no command-line options of its own; ``-h`` is an illegal argument. The interpreter flags come from the environment. Commands of the REPL ==================== A line that starts with a colon is a command. Any other line is an expression, which the REPL evaluates as ``:eval`` does. A command name may be any unambiguous prefix, for example ``:e`` for ``:eval`` and ``:t`` for ``:type``. The prompt splits a line at whitespace and joins the words with one space before the front end sees them. So ``putStrLn "a b"`` prints ``a b`` at the prompt. An argument given on the command line is taken as it is. ``:load FILE`` Compiles and imports the Curry module in ``FILE`` and adds its directory to :data:`curry.path`. The prompt names the module. The expressions of ``:eval`` and ``:type`` see the symbols of that module and of the Prelude, and nothing else: the imports of the module are not in scope at the prompt, and no command imports another module. To use a function of a library at the prompt, define a wrapper in the loaded module, or re-export the library from it (``module M (module M, module Control.SetFunctions) where``). A module loaded already is not read again in this process: a second ``:load`` of it after an edit of the file returns the module as it was loaded and prints a warning that names the module and the file, once per ``:load``. A ``:load`` of another file of the same module name does the same, and the warning names both files. Quit the REPL and start it again to load the edited or the other file. ``:eval EXPR`` Compiles the expression, evaluates it, and prints each value on a line of its own. Class constraints are defaulted as described below. ``:type EXPR`` Prints the type of the expression as the front end infers it, with its class context and before any defaulting: ``1+2 :: Num a => a``. ``:set OPTION VALUE``, ``:set [+|-]OPTION`` Sets an option. ``:set`` alone lists the options and their state. The options are: ``backend`` The backend of the session. ``:set backend NAME`` switches the session to that backend: the interpreter is reloaded and the module is loaded again. If that load fails, the session stays on the new backend with the Prelude at the prompt, and the next ``:load`` or ``:set backend`` loads the module again. ``internal-error-details`` A Boolean option. ``:set +internal-error-details`` adds the Python traceback to the report of an error during an evaluation; ``:set -internal-error-details`` removes it again. The other settings of the interpreter, such as ``rotation`` and ``interpret``, are not options of ``:set``; they come from ``SPRITE_INTERPRETER_FLAGS`` and ``SPRITE_ROTATION`` in the environment when the REPL starts. ``:quit`` Exits. Commands may also be given on the command line. Each command starts with its colon and takes the words that follow it. An error in such a command ends the REPL with the status 1. An error at the prompt prints its message and the loop continues. .. code-block:: bash % install/bin/python -m curry.tools.icy :load Goals.curry :eval main14 :quit Just 5 A session with a module ======================= The transcript below is the part of one session that lists the options and loads a module. ``Goals.curry`` holds ``double x = x + x`` and ``main14 = Just 5``. The sections that follow quote the other exchanges of the same session. .. code-block:: text Prelude> 1 ? 2 1 2 Prelude> :set Usage: :set