Tianxiang Xiong
Tianxiang Xiong

Reputation: 4081

Common Lisp `format` implementation

Is there a particularly easy to read implementation of Common Lisp's format?

I've found SBCL's version, but since SBCL has a reputation for being a performant implementation of Common Lisp, I'm wondering if there's an implementation that focuses more on clarity and readability.

To be fair, SBCL's version isn't too hard to read, and I don't see a lot of optimizations, but if there's a more reader-friendly version I'd like to know about it!

Upvotes: 2

Views: 329

Answers (1)

coredump
coredump

Reputation: 38809

I don't see a lot of optimizations.

They are elsewhere. Just typing "format" in the REPL under Emacs+Slime and typing M-. brings up a buffer with the different locations associated with the symbol, including optimisations:

###/sbcl-1.3.7/src/code/cmacros.lisp
  (DEFINE-COMPILER-MACRO FORMAT)
###/sbcl-1.3.7/src/code/target-format.lisp
  (DEFUN FORMAT)
###/sbcl-1.3.7/src/compiler/srctran.lisp
  (:DEFTRANSFORM FORMAT (NULL (SB-INT:CONSTANT-ARG STRING) &REST STRING) "optimize")
  (:DEFTRANSFORM FORMAT (NULL FUNCTION &REST T) "optimize")
  (:DEFTRANSFORM FORMAT ((MEMBER T) FUNCTION &REST T) "optimize")
  (:DEFTRANSFORM FORMAT (STREAM FUNCTION &REST T) "optimize")
  (:DEFTRANSFORM FORMAT (T SIMPLE-STRING &REST T) "optimize")
  (:DEFOPTIMIZER FORMAT SB-C:DERIVE-TYPE)
  (:DEFOPTIMIZER FORMAT SB-C:OPTIMIZER)
###/sbcl-1.3.7/src/compiler/fndb.lisp
  (DECLAIM FORMAT SB-C:DEFKNOWN)

[...] but if there's a more reader-friendly version I'd like to know about it!

You can read CLisp's version online on the non-official github repository; or Clozure CL's implementation. Look also at ABCL's format.lisp, as well as ECL, etc. I can't provide a link to each Common Lisp implementation (see this page for a list). From what I could see they all tend to have a lot of comments, but whether you find one more readable than another is up to you.

Upvotes: 6

Related Questions