Previous: Modules, Up: Scheme reference [Contents][Index]
The (hoot repl) module provides a procedural API for
read-eval-print loops. Additionally, it comes with a built-in driver
for a purely text-based REPL interface. New drivers can be created by
integrating the procedural API with the desired interface, such as the
web’s document object model.
REPLs contain a set of meta-commands and a stack of environments that can be pushed and popped.
Return a fresh REPL for environment with meta-commands.
Return #t if obj is a REPL.
Return the current environment for repl.
Return the stack of previous environments for repl.
Return the current depth of repl.
Return the welcome message for the current environment in repl.
Return the current prompt message for repl.
Return a list of meta-commands associated with repl.
Return the meta-command in repl associated with name, or
#f if there is no such command.
Add meta-command cmd to repl.
Enter a sub-REPL within repl using env, saving the current environment on the environment stack to be restored later.
Leave the current environment in repl, restoring the previous environment if there is one. Otherwise, raise an exception.
Read an expression from port using the current reader for repl. The returned expression may be a meta-command invocation.
Eval exp in the current environment of repl.
Eval exp, either a language or meta-command expression, in the current environment of repl. If an exception is thrown while evaluating a language expression, a debugging sub-REPL will be entered.
Invoke the meta-command cmd in repl with args.
Parameter containing the current REPL being used for evaluation. Can be used in evaluated code to manipulate the host REPL.
The procedures below provide a classic textual REPL driver.
Run repl using reader to prompt the user and read input. A default reader is used if none is specified.
Reader procedures take a REPL object as their only argument. Readers should display the current prompt and parse an input expression with the repl-read procedure.
Create and run a REPL for environment with meta-commands.
Environments are the context in which evaluation occurs. They contain a module (see Modules) and a language for parsing and evaluating REPL input.
Return a fresh REPL environment for evaluating language in module. data can be any arbitrary object to associate with this environment, perhaps including debug information. welcome is a procedure that displays a welcome message when the enviroment is entered. prompt is a procedure that returns an input prompt to display to the user. Both welcome and prompt take just one argument: a REPL object.
Return #t if obj is a REPL environment.
Return the language for env.
Return the module for env.
Return the custom data for env.
Return the welcome procedure for env.
Return the prompt procedure for env.
Languages encapsulate a title string, a reader procedure, and an evaluator procedure. So, in theory, the Hoot interpreter could host many languages, like the Guile VM does. In practice, at least for now, the language is always Scheme.
Return a new language named title that parses input text with reader and evaluates expressions with evaluator. reader is a procedure of one argument: an input port. evaluator is a procedure of two arguments: an expression to evaluate and a module in which to perform the evaluation.
Return #t if obj is a REPL language.
Return the title of lang.
Return the read procedure for lang.
Return the evaluation procedure for lang.
Meta-commands are special REPL tools that can be invoked using a comma
at the beginning of the expression, such as ,help. New
meta-commands can be defined using define-meta-command.
Define a meta-command named name with an associated procedure
containing body that accepts repl and additionally any
other args. The arguments list may include optional and keyword
arguments as in define*.
Additionally, there are several meta-command properties that may be specified via kwargs:
#:nameThe symbol used to invoke this meta-command at the REPL prompt.
#:aliasesA list of symbols, each of which is an alternative name for this meta-command.
#:groupThe name of the meta-command group as a symbol. Related meta-commands should belong to the same group to ease user discovery.
#:usageA string that describes how to invoke this meta-command. A
meta-command with a required argument foo and an optional
argument bar might have the usage string "FOO [BAR]".
#:summaryA brief documentation string.
#:documentationA detailed documentation string.
#:readerA procedure that reads meta-command arguments. It takes two arguments: a repl and a port. This is an advanced configuration option for meta-commands that need special argument parsing logic. The default reader is usually sufficient.
This macro is best explained by example:
(define-meta-command (meta:say repl #:optional message) ;; Keyword arguments: #:name 'say #:aliases '(s) #:group 'example #:usage "[MESSAGE]" #:summary "Say something." #:documentation "Say a few words, or maybe don't say anything at all." ;; Procedure body: (if message (format #t "You said: ~a\n" message) (display "You didn't say anything.")))
Once added to a REPL with (repl-add-meta-command! repl
meta:say), it can be invoked with ,say or its alias ,s:
(hoot user)> ,say "Hello!" You said: Hello! (hoot user)> ,s You didn't say anything.
Return #t if obj is a meta-command.
Return the name of cmd.
Return the aliases of cmd.
Return the documentation for cmd
Return the documentation for cmd
Return the documentation for cmd
Return the procedure used to read arguments for cmd.
Return the procedure used to perform cmd.
Previous: Modules, Up: Scheme reference [Contents][Index]