Interactive work with Scheme code (Lepton EDA Reference Manual 1.9.18)

### 5.16 Interactive work with Scheme code ¶

You can extend the functionality of `lepton-schematic`, automate some work on schematic or symbol creation, and learn how things are internally made up playing with Scheme without even exiting the program. There are several ways to get things done and they are described below.

> Note: You can also work with Scheme using interactive mode of several non-GUI Lepton utilities, namely, `lepton-netlist`, `lepton-cli`, and `lepton-symcheck`. Please read their manual pages on how to run them interactively.

Sometimes it is very convenient to invoke a one-line script to try some idea. Use File → Invoke macro... (`:`, colon, or `E Shift-:`) to open a macro widget which will allow you to execute some small excerpts of Scheme code interactively. In the macro widget entry you may enter one line consisting of one or more commands in Scheme (don’t forget parentheses). Hit `Enter` to make them evaluate and watch the result of your expression in the Log window. If the script includes some interactive functions, you’ll immediately see the result in GUI.

Another, more powerful possibility is executing a Scheme script stored in some file in your file system. It allows you evaluate the code of any length, so it is much more convenient if you work on some complex code. Use File → Execute Script... (`F T`) and select a Scheme script to execute. You can filter the files like in the File Open dialog (see Creating new and opening existing schematic files), though you can choose solely amongst showing only Scheme or any files. Switch between `lepton-schematic` and your text editor, edit your code and try again.

The most powerful and convenient way of working with Scheme is using REPL. There are two ways to start it:

- Use File → REPL... (`F Shift-R`) to start REPL in the background terminal where you started `lepton-schematic`, move to the terminal and hack your Scheme code interactively. If you didn’t use a terminal for launching the program, the feature is not available.
- Launch the following code in the macro widget described above, in the command line using the `-c` option (see lepton-schematic command line options), or in one of RC files available for your project (see `gschemrc`):

      (use-modules (system repl server)) (spawn-server)

  The command will make available a Scheme socket on the port 37146 for your program. You can connect to it, for example, using `netcat` or shiny `geiser` environment for `Emacs`, and enjoy working with REPL using the program chosen.

In the REPL, you’ll immediately see the results of your expressions or errors, be able to list, edit and use expressions evaluated before, utilize their results again, load files, and more. So this option embraces all the advantages of the former two and adds more. However, be careful:

> Caution: Trying some code pieces may be dangerous and crash your running `lepton-schematic` process while working in the REPL! The reason is the lack of proper multi-threading support in GTK while Scheme supports it pretty well. If in doubt, save your designs before trying something out.