Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source code documentation in Racket (Scheme)

Tags:

scheme

racket

Is it possible to write documentation in source files like in Common Lisp or Go, for example, and extract it from source files? Or everybody uses Scribble to document their code?

like image 611
hsrv Avatar asked Dec 26 '18 22:12

hsrv


People also ask

Is racket a Scheme?

Racket is a fork of Scheme, the simple language at the core of this course for many years. Scheme was created primarily as an experiment in understanding how programming languages work. Racket retains its basic favor, but it also adds many, many features that make the language useful in the 21st century.

Is racket similar to Lisp?

Racket is a descendant of Scheme, which in turn is a descendant of Lisp. So while Racket is not Lisp (in the specific Common Lisp sense), it is a Lisp (in the familial sense). Its core ideas—and core virtues—are shared with Lisp.


1 Answers

The short answer is you can write in-source documentation by using scribble/srcdoc.

Unlike the other languages you mentioned, these aren't "doc strings":

  • Although you can write plain text, you have full Racket at-expressions and may use scribble/manual forms and functions.

  • Not only does this allow for "richer" documentation, the documentation goes into its own documentation submodule -- similar to how you can put tests into test submodules. This means the documentation or tests add no runtime overhead.

You do need one .scrbl file, in which you use scribble/extract to include the documentation submodule(s). However you probably want such a file, anyway, for non-function-specific documentation (topics such as introduction, installation, or "user's guide" prose as opposed to "reference" style documentation).

Of course you can define your own syntax to wrap scribble/srcdoc. For example, in one project I defined a little define/doc macro, which expands into proc-doc/names as well as a (module+ test ___) form. That way, doc examples can also be used as unit tests.

How Racket handles in-source documentation intersects a few interesting aspects of Racket:

  • Submodules let you define things like "test-time" and "doc-time" as well as run-time.

  • At-expressions are a different syntax for s-expressions, especially good when writing text.

  • Scribble is an example of using a custom language -- documentation-as-a-program -- demonstrating Racket's ability to be not just a programming language, but a programming-language programming language.

like image 152
Greg Hendershott Avatar answered Oct 23 '22 02:10

Greg Hendershott