line-readtable

2026-11-29

Describe line-readtable here

Upstream URL

Author

Artyom Bologov

License

BSD-2 Clause
README

1line-readtable

line-readtable is a readtable library suited for line editing of Lisp code.

line-readtable stems from my (aartaka) desire to edit Lisp in line-based environment. This is hard. The code needs big adjustments or heavy syntax changes. Thus the need for new reader macros. I cannot use them in open source libraries without packaging them into a library of their own, though. So here’s the library with macros for Lisp line editing, packaged in a named readtable: line-readtable!

Here’s how a factorial function looks with hash-slash macro provided by line-readtable, for example:

  ;; Useful for macros like with and whether
  (use-package :line-readtable)
  ;; For syntax like #/ and []
  (named-readtables:in-readtable line-readtable:line-readtable)
  (defun factorial [n]
    (if #/ < n 2
        1
        #/ * n #/ factorial #/ 1- n))

1.1Getting Started

1.1.1Library user setup

If you want to use the library without hacking on it, clone the Git repository to where ASDF can find it:
  git clone https://codeberg.org/aartaka/line-readtable ~/.local/share/common-lisp/source/

And then load ~"line-readtable"~ in the REPL:

  (asdf:load-system "line-readtable")
  ;; or, if you use Quicklisp
  (ql:quickload "line-readtable")

Using it after that is either adding a form to the top of each code file:

  (named-readtables:in-readtable line-readtable:line-readtable)

or merging the line-readtable with the standard readtable

  (named-readtables:merge-readtables-into *readtable* line-readtable:line-readtable)

1.1.2Contributor/developer setup

In case you want to hack on line-readtable, all the dependencies are bundled as submodules, you need to do a recursive clone
  git clone --recursive https://codeberg.org/aartaka/line-readtable

In case you initially cloned the repository without submodules, do

  git submodule update --init -- deps/

After that, you can run

an Emacs-friendly development server
make slynk or make swank
REPL with all the dependencies and line-readtable preloaded
make repl
tests
(asdf:test-system "line-readtable") or run make check from CLI.

1.2Provided utilities

Non-syntax utilities provided by line-readtable:

  • with macro as a less verbose version of let* removing unnecessary level of parens around binding.Stolen from Clojure let.
  • whether macro as a less parenthesized version of cond.Every pair of forms is a condition+clause pair.To get the regular cond behavior, one would have to wrap multiple forms in progn, but such is the price.Idea stolen from Clojure cond, again.

1.3Provided Syntax

Overall, see tests for what the syntax expands to and how it might be used.But here’s an overview.

1.3.1#^ lambdas

Shorter anonymous functions #^v.(fn arg1 arg2) to save on all the parentheses needed for lambda.The syntax is vars.body.Where vars is a non-delimited string of up to three single-char vars (abc is a, b, and c vars)to be bound to optional ignorable lambda args.And body is any Lisp form.

1.3.2#/ hash-slash operator

Behaves like Wisp’s inline colon operator, reading the form until the end of the line or end of wrapping form, as a parenthesized list. I.e.
  (+ 1 #/ * 2 3 #/ - 4 5)
  ;; Is the same as
  (+ 1 (* 2 3 (- 4 5)))

Note that this syntax is newline-sensitive, so adding a newline nullifies/closes any stack of hash-slashes you had. This is unlike Wisp, where colon sometimes can stretch for multiple lines when augmented with indentation. Also note that indentation doesn’t influence hash-slash!

  (+ 1 #/ * 2 #/ + 3
     (- 4 5))
  ;; Is the same as
  (+ 1 (* 2 (+ 3))
     ;; Notice this form is not part of the * 2 above
     (- 4 5))

1.3.3Square bracket [1 2 3] lists

This is stolen from Scheme, where square brackets are roughly equivalent to parentheses.It’s useful for e.g. let bindings to disambiguate separate bindings:
  (let ([a 3]
        [b 4])
    (+ a b))

While this syntax addition might seem orthogonal to line editing, it isn’t. Having a varied set of delimiters means regex in line-based editors (like ed) can easier manipulate forms. Thus the addition.

Dependencies (4)

  • lisp-unit2
  • named-readtables
  • slime
  • sly

Dependents (0)

    • GitHub
    • Quicklisp