Skip to content

Interacting with an Interpreter

Harry Pantazis edited this page Jun 9, 2017 · 1 revision

Interacting with an interpreter

The embedded Kawa interpreter

It is possible to interact with the Kawa interpreter embedded in the SchemeScript plugin. Using this interpreter, one can script Eclipse in Scheme. For example, most of the functionality in version 1.0.0 has been developed interactively using this interpreter.

Kawa Stack trace View

When an error occurs in the interpreted code, the stack trace can be display in the Kawa Stacktrace View:

Kawa Scratchpad

The Kawa interpreter can also be used to test custom SWT/JFace controls developed in Kawa Scheme. To do this, call the add-scratchpad-view function with two parameters: a symbol for identifying the view, and a function of one argument that will be called to create the control in the parent control passed in argument.

The file examples/circles.scm that can be found in the plugin distribution is an example of such a control created in Scheme. Here is the result of loading this file:

Connecting to a remote Scheme interpreter

Many Scheme interpreters can be started in server mode, waiting for another process to connect on a specific TCP/IP port number. The remote interpreter interface allows SchemeScript to communicate with such interpreters.

The SchemeScript remote interpreter interface is SISCweb ready, i.e. it will connect to port 5156 on localhost by default. This can be changed using the preference page.

Interacting with an external Scheme interpreter

SchemeScript provides a minimal interface external to Scheme interpreters.

Configuring the interpreter

To configure a Scheme interpreter, open the External Interpreter preference page.

Extracting error locations

When an error occurs in the interpreter, SchemeScript can turn the location of the error into an hyperlink (given that it is appropriately configured). Here is the result of an interaction with the MzScheme interpreter:

Clicking on the hyperlink will open the file containing the error and select the line containing the error.

Launching the interpreter

To launch the interpreter from the Scheme perspective, select the interpreter using the "Scheme/Select Interpreter" menu item, and then select the "Scheme/Start Interpreter" menu item or click on the "Start Interpreter" toolbar button. The interpreter will be accessible from the Console View:

In this example, an external Kawa interpreter is run.

Sending expressions to the interpreter

S-expressions can be sent directly to the interpreter for evaluation using the Eval Expression and Eval toplevel Expression commands from the editor ( à la Emacs). See Editing.

For example, suppose that the cursor is located after the closing parenthesis in:

Pressing Ctrl-Enter will send to whole expresssion (the define form) to the interpreter. Also, pressing Ctrl-Shift-Enter will send to the interpreter the top-level expression that encloses the cursor position.

The whole editor content can be sent to the interpreter using the Load File in Interpreter command, which is bound to the Ctrl-Shift-L key sequence by default.

Interrupting an evaluation

Note: This applies only to external interpreters.

If the external interpreter supports interruption using kill -2, follow these steps before starting the interpreter:

  • Check the "Interpreter saves PID" check box in the "Scheme/External Interpreter" preference page.
  • Pass the name of the file where the PID of the Scheme process must be stored to the Scheme interpreter using the {pidfile} variable on the command-line arguments. The Scheme process must then save its PID in the given file. (Most Scheme system allow the evaluation of command-line arguments).

To interrupt an evaluation, simply select the "Scheme/Interrupt Evaluation" menu item or press ALT-F9 in the Scheme perspective. You can also click on the corresponding toolbar button.

Fast Eval keys

Fast Eval keys are configurable commands that send predefined expressions to the interpreter. These expressions are configured in the Fast Eval preference page.

For example, suppose that Fast Eval Key #0 is set to (test). Every time the Fast Eval 0 command is run (by pressing Alt-K 0 by default), the string (test) is sent to the interpreter.