Paolo Amoroso's Journal

Interlisp

I integrated Femtounit with the File Manager by defining the new type TESTS for Femtounit tests and redefining DEFTEST in terms of it.

It turns out it's not a good idea as the tests get duplicated. The DEFTEST macro expands into a DEFINEQ function definition and the File Manager notices both, the DEFTEST form of type TESTS and the function of type FNS.

The fix seemed simple, assigning tests to an existing type such as FNS. First I removed TESTS with (DELDEF 'TESTS 'DEFINE-TYPES), then replaced the type argument TESTS with FNS in the XCL:DEFDEFINER form. But when I tried to edit a sample test TEST.PLUS for the PLUS function with (ED 'TEST.PLUS :DONTWAIT), SEdit quit with the error:

Warning: Couldn't find a hash-table for FNS definitions.
One will be created.
Could not find fns definition for TEST.PLUS.
Could not find fns definition for
TEST.PLUS

Back to the drawing board.

#femtounit #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

I integrated Femtounit, my Interlisp unit test framework, with the File Manager and the SEdit structure editor.

To achieve this I defined the new File Manager type TESTS for Femtounit tests and redefined DEFTEST in terms of it, then tweaked the code formatting of tests in SEdit. Now the system notices and keeps track of new and modified tests.

Here's the File Manager type menu, which SEdit pops up when opening a test, with the DEFTEST option highlighted under TESTS:

Interlisp File Manager menu with the Femtounit types.

Also, now SEdit handles and properly formats test definitions like this of a function SQUARE to compute the square of its argument:

SEdit editing a Femtounit unit test definition on Interlisp.

Implementing the new features was much easier than expected.

The traditional way of adding types to the File Manager, described in the Interlisp Reference Manual, involves writing a dozen functions for most of which it's not clear how they're supposed to work. Medley 1.0 added support for two easy to use File Manager type defining forms that replace all that, XCL:DEF-DEFINE-TYPE and XCL:DEFDEFINER. This code is all it took for Femtounit's new TESTS type:

(XCL:DEF-DEFINE-TYPE TESTS "Femtounit unit tests")

(XCL:DEFDEFINER (DEFTEST (:PROTOTYPE
                            (LAMBDA (NAME)
                              (AND (LITATOM NAME)
                                   `(DEFTEST ,NAME ("Arg List")
                                      "Body")))))
                TESTS
                (NAME PARAMETERS &BODY BODY)
   `(DEFINEQ (,NAME ,PARAMETERS
      (LET ((FTU.TEST.NAME (APPEND FTU.TEST.NAME (LIST ',NAME]
        ,@BODY))))

This additional tweak makes SEdit format and indent DEFTEST unit test definitions the same way as DEFUN function definitions in Common Lisp:

(SEDIT:DEF-LIST-FORMAT DEFTEST CL:DEFUN)

The simplified process is not discussed in the Interlisp Reference Manual, where I'd have expected, but in a more obscure source, the Medley 1.0 release notes from page 52 of the PDF document. My proactive reading of all the documentation paid off as it let me spot such crucial information and save a lot of work.

#femtounit #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

I'm writing another Interlisp program, Sysrama, an Interlisp documentation tool for presenting information on the Lisp objects of a program. It produces reports that list the types and signatures of functions, the fields of records, global variables, property lists, Executive commands, and more.

The way I reference the details of Lisp objects when coding gave me the idea for Sysrama.

I often forget the names and signatures of the functions or the names of the record fields I need. Browsing or looking up the code for referencing them is a source of friction.

Interlisp comes with the powerful program analysys tool Masterscope that gives its best with answering specific questions on the internals of programs. But it has a steep learning curve and it doesn't provide the kind of big picture view I seek. Instead, I wanted a simple tool for producing an overview of the main Lisp objects in a program.

This is a sample report Sysrama prints on another of my Interlisp programs, Stringscope:

Sample output of the Sysrama documentation tool for Interlisp.

The main sections group objects under the same File Manager types, such as FNS or RECORDS. This is because Sysrama can extract information only from programs under File Manager control.

Suppose you want to analyze the Lisp program MYPROG. Once Sysrama is in memory, load MYPROG:

(LOAD 'MYPROG)

To have Sysrama print a report with information on MYPROG evaluate:

(SUMMARIZE 'MYPROG)

You can narrow down the information to specific File Manager types such as FNS and RECORDS:

(SUMMARIZE 'MYPROG '(FNS RECORDS))

or to specific objects like the function MYFUN:

(SUMMARIZE 'MYPROG 'FNS 'MYFUN)

More documentation is available at the project repo.

Sysrama already does most of what I had in mind but I'll implement a few more features.

I'll tweak the reports to show more information on some Lisp objects. And I'll add the ability to redirect the output to a scrollable window rather than to the primary output stream. By default Interlisp windows don't save the output history and can't be scrolled back, so such a feature will help review reports that don't fit in a window.

#sysrama #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

Medley is a rich development environment but it's missing a test framework. Or so I thought. To fill the supposed gap I wrote Femtounit, a tiny — hence femto — unit test framework for Interlisp.

I wanted a small framework simple to port to or write for Interlisp, yet useful in practice. At less than a couple dozen lines of code, Femtounit took very little effort to design and write as it's based on the PCL test framework Peter Seibel described in Chapter 9 of his book Practical Common Lisp.

I reused much of Peter's design and code, adapting it to Interlisp and tweaking the reporting of tests. Femtounit outputs a single period character for every passed test, unlike the full report his framework prints.

Using Femtounit looks like this:

Usage of the Femtounit unit test framework for Interlisp.

Suppose you want to test this function that returns the square of its argument:

(DEFINEQ (SQUARE (X) (TIMES X X)))

You may define a TEST.SQUARE test function like this:

(DEFTEST TEST.SQUARE ()
  (CHECK.EXPECT (EQP (SQUARE 1) 1)
                (EQP (SQUARE 2) 4)
                (EQP (SQUARE 3) 9)
                (EQP (SQUARE 4) 16)))

To run the tests, just call the function:

(TEST.SQUARE)

which will print a period character for every passed test:

....

Some documentation is at the project repo.

After I finished the initial code of Femtounit, Larry Masinter pointed out Medley does have a test framework, and quite an advanced one. This system, which the Medley documentation simply calls test system and is much more than a framework, was originally designed to test Interlisp and its environment. The code is now in one of the Medley repos.

I thought I explored every nook and cranny of Medley and its documentation, yet I missed the test system. The system is interesting in itself and I'll use it for most of my code.

But Femtounit is a fun little learning project I still want to proceed with. It'll teach me how to integrate the framework with Interlisp for editing unit test definitions with the SEdit structure editor, as well as saving the definitions to files and managing them with the make-like File Manager tool.

#femtounit #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

I'm back to work on Braincons, a Brainfuck implementation I'm developing with Medley Interlisp.

The new code I wrote implements the virtual machine (VM) and executes the Braunfuck instructions. Now Braincons can create and reset a VM, load a program into it, and execute the program until completion or for a designated number of steps.

The Lisp record BRC.VM represents the VM and holds the Brainfuck program, memory, machine state such as the instruction and memory pointers, and virtual I/O devices. All the functions that operate on the VM accept a BRC.VM record as an argument, update it as necessary, and return the record.

To decouple as much as possible I/O from other subsystems, BRC.VM contains the IN and OUT fields to hold a Lisp input stream and a Lisp output stream.

Any functions that need to read data or display output on behalf of the VM can do I/O to the relevant VM streams. This adds flexibility as most Interlisp text and window output functions accept streams as arguments.

Having the book A Philosophy of Software Design fresh in my mind after recently reading it, to design the Braincons VM I deliberately sat down to think about and write a specification of how the features needed to work. Although the book presents a lot of material I haven't absorbed yet, this preliminary work helped me design a relatively small and clean VM interface and saved some code rewriting.

Now that Braincons can parse, compile, and execute Braunfuck programs, the next step will be to build the user interface for editing and running programs, as well as inspecting the VM and its state.

#braincons #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

I finished implementing the commands of Stringscope, the string listing tool I'm developing with Medley Interlisp.

After Sort, Reset, and Exit I wrote the code for Min Len, Find, and Get. I also added the new command Info to show in the prompt area some statistics about the strings. Coding the other commands gave me the idea and Implementing Info seemed easy, so I did it.

Now Stringscope looks like this, with the prompt area attached to the top side of the main window and the menu at the right side:

Window of the Interlisp program Stringscope with an advanced version of the command menu.

I renamed the menu item Set threshold to Min Len as the former was too wide and stood out. Min Len is more consistent with the documentation and code of Stringscope. In addition, I centered the items instead of aligning them flush left. This is the more idiomatic way most traditional Interlisp programs and system tools lay out menus.

To explain how the commands work I recorded a screencast that walks through the features and input validation of Stringscope.

I demonstrated the program by opening and interacting with two binary files, the DOCTEST.TEDIT document created with the TEdit rich text editor and the program's compiled executable STRINGSCOPE.LCOM. I also threw in some invalid data as input to show input validation in action.

After writing the code of the commands I realized Stringscope grew to support all the features I initially planned, plus a couple more I thought of along the way.

Medley Interlisp seemed overwhelming and intimidating at first but it was too much fun, so I pressed on using and studying the system. The effort paid off and now I can not only find my way around, but also create a small yet complete program with a GUI. This is a milestone to celebrate.

It's probably time to ship version 1.0 and start thinking of how to improve Stringscope and its design.

#stringscope #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

I'm having a lot of fun working on the commands of Stringscope, the string listing tool I'm developing with Medley Interlisp.

I implemented the Sort menu item with its subitems Ascending and Descending, as well as the Reset item. I added also the Exit item for quitting the program, a low-hanging fruit that just required calling the CLOSEW window manager function for closing the main window.

The main window of Stringscope, the command menu, and the prompt area now look like this:

Window of the Interlisp program Stringscope with an early version of the command menu.

The commands didn't require too much new code. I take it as a sign the foundation is solid, or at least not too shaky. And Interlisp's powerful menu system made things easier. But there's some code duplication I'm not satisfied with that will need refactoring.

The next commands to implement are the ones that take input from and output to the prompt area: Get, Find, and Set threshold.

#stringscope #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

I'm enhancing Stringscope with a permanent command menu and a prompt area. The menu, an item of which holds a submenu, attaches to the right side of the main window, the prompt area to the top of the main window above the title bar. This is what the main window looks like now:

Window of the Interlisp program Stringscope with an early version of the command menu.

This way of arranging menus and secondary windows by attaching them to a main window is typical of Interlisp programs with a GUI. The system supports this design with functions like the ones I used, CREATEMENUEDWINDOW to create and attach a menu and GETPROMPTWINDOW for doing the same with a prompt window.

The menu comprises these initial items and subitems:

  • Get: reads the strings of a new file
  • Find: searches for strings matching a specific text
  • Sort: sorts the strings in the following order
    • Ascending
    • Descending
  • Set threshold: changes the minimum length of strings
  • Reset: redisplays the strings read from the current file

The prompt window is an area for displaying status messages and receiving user input such as the name of a new file to read.

So far the Stringscope code sets up the menu and the prompt window. The menu handling function, however, is just a stub that prints to the main prompt window the selected menu item.

The next step will be to implement the commands the menu calls.

#stringscope #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

I moved the Stringscope project infrastructure from a GitHub gist to a full repo. The gist is now unmaintained and links to the repo.

Announcing my new Interlisp project Braincons I motivated setting up its infrastructure as a repo with a number of reasons boiling down to convenience. Code is still readble despite the formatting Interlisp encodes, source files no longer need conversion, and a full repo is more flexible. I moved Stringscope to a repo for the same reasons.

#stringscope #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org

After Stringscope I've been working on Braincons, an Interlisp implementation of the esoteric programming language Brainfuck. The project goals are to further learn the Medley Interlisp environment I'm developing Braincons with, as well as experiment with the compilation and implementation of a very simple language.

Braincons data structures inspected in Medley Interlisp.

Status

Braincons is in an early stage of development and largely incomplete, so I don't have much to show yet.

There's no program, output window, or Executive command to run. But preliminary versions of some of the main functions and data structures are in place, which can be called and inspected from Lisp.

So far the system can only parse Brainfuck program sources, check for errors, and produce an intermediate representation a virtual machine will eventually execute.

Installation

To try out Braincons download the file BRAINCONS from the project repo, copy it to a file system your Medley Interlisp installation has access to, and evaluate the following expression from the Lisp Executive:

(FILESLOAD BRAINCONS)

Usage

At this point you can call the parser function BRC.PARSE and pass it a Brainfuck source string:

(SETQ PARSED.PROGRAM (BRC.PARSE "<>[.,]+-"))

BRC.PARSE returns the intermidiate representation of the source, then assigned to the variable PARSED.PROGRAM which you can inspect as a BRC.PROGRAM record:

(INSPECT PARSED.PROGRAM)

The inspected record and its fields should look similar to the above screenshot. This is all I have for now.

Design

I initially focused on designing the main data structures and functions upon which to build the rest of Braincons.

First, I assigned descriptive mnemonics to the Brainfuck commands as in this table:

Command Mnemonic
> NEXT
< PREV
+ INC
- DEC
. OUT
, IN
[ JZ
] JNZ

Braincons represents the source of a Brainfuck program as a string. Two data structures implemented as Interlisp records hold the intermediate representation the parser produces.

The record BRC.PROGRAM consists of an array of instructions, the index of the last instruction in the array, a list of any branch instructions in the source, and a list of any errors encountered while parsing the program. Each array entry holds a Lisp symbol of the mnemonic of the corresponding instruction, except for the branch instructions JZ (jump if zero) and JNZ (jump if not zero).

Branches are records with fields for the mnemonic, the source address in the instruction array, the destination address, and the index of the branch command in the source string.

So far Braincons has only one entry point, function BRC.PARSE, which takes a Brainfuck source string as the only argument and returns the parsed intermediate representation record BRC.PROGRAM. BRC.PARSE calls directly or indirectly some helper functions to parse individual instructions, create branch records, and check for errors.

Sharing

Along with ASCII characters, Interlisp source files contain special characters such as and control codes that encode font changes. Visualizing these files in editors and tools that expect ASCII thus shows spurious characters.

To work around this I didn't directly share the raw code of Stringscope. Instead I stripped the control and formatting codes from the source exported from Medley Interlisp, replaced the special characters with more readable versions, and published it to a GitHub gist. The code in the gist is nicely formatted for reading but Medley Interlisp can't load it as is, so I have to provide the raw source separately.

Since Interlisp programmers are used to the formatting, and cleaning it up involves additional steps, I decided to store the raw source of Braincons in a GitHub repo. This also provides the additional flexibility of a full repo.

Further development

I'm actively changing and enhancing the code of the only working feature, the parser. Although the basic design of the main data structures is stabilizing, everything else will likely need a lot of refactoring and cleanup.

Next, I'll implement the virtual machine that processes and executes the parsed program.

In the long term I'd like to build a minimal Brainfuck development environment on top of the parsing and program execution functionality. The environment will comprise a source editor based on TEdit and an interactive visualization with controls for loading and starting programs, showing the state of the virtual machine and the executing program, reading user input, and displaying the output.

#braincons #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org