Re: Factor

Factor: the language, the theory, and the practice.

Quit

Wednesday, June 12, 2024

There is a funny recurring meme that we are all living inside a simulation or maybe even a matrix-in-a-matrix. Some people have even taken this as far as selling funny computer simulation t-shirts:

Well, I have resisted for a long time adding a special end programquit – command to Factor. We have always supported Ctrl-D to end the listener session (which works in both the UI listener and in the command-line on most POSIX systems). You have also been able to exit with an error code, or even to stop after the last window has been closed. And if you really needed something, you could define your own end program word in your startup initialization file.

This came up again recently in a discussion with @nomennescio, one of our contributors, who has been pushing for a quit command that would be kind of like the Python version of How to Exit a Python Program in the Terminal:

Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
>>> quit()

This has become more important since they added saving listener history to the UI tools (currently saved to a history file when the listener window closes). This was paired with a couple of changes to make Factor attempt to close-all-windows and cleanup nicely using a shutdown hook and include the system vocabulary in the default list of interactive vocabularies.

This means that this works now, in both the command-line listener as well as the UI listener:

Factor 0.100 x86.64 (2271, heads/master-250db4215b, Jun  4 2024 18:08:03)
[Clang (GCC Homebrew Clang 18.1.6)] on macosx
IN: scratchpad quit

If you’re curious how it works, quit is an alias for calling exit with an error code of 0:

IN: system

: quit ( -- * ) 0 exit ;

This is available in a development version of Factor and will be in the next release.