💾 Archived View for gemini.ctrl-c.club › ~stack › gemlog › 2021-11-01-gemlit.gmi captured on 2022-04-29 at 12:38:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-03-01)

-=-=-=-=-=-=-

gemlit - Literate Programming for Gemini

I wrote a minimalist utility to support literate programming for Gemini.

gemlit.c

gemlit <filename> (<comment-marker>)

TLDR: it comments everything except pre-formatted text blocks. I've seen others simply extract such code, but this way any errors will refer to meaningful line numbers.

I don't know how I feel about literate programming. If you are not familiar with it, I suggest you search the web for an infinity of better explanations than I could come up with. Donald Knuth wrote a book about it, and a whole system to support it. TLDR: source code is mixed with human-only prose in a way that is readable and compilable (or interpretable).

I haven't done nearly enough (or anything) with it to have an opinion. I wanted to give it a try to see if it's just too much extra work, but most of what's out there is not what I want to deal with, so I put together a tiny C program that allows arbitrary mixing of gemtext and code. To see a really poor example of literate programming, look at the linked .gmi file which contains the actual gemlit utility:

gemlit.gmi

If you have gemlit installed, you can run it on the file and pipe the output into gcc, so it can compile itself:

gemlit gemlit.gmi | gcc -o gemlit1 -xc -

This works for simple one-file programs. For larger programs you can keep your source as literate gemfiles, and use a makefile to create .c files, then compile them (for instance.

You are not limited to C/C++, of course. Simply specify the comment-marker parameter that works with your language. For Lisp, use ';;' - including the quotes.

As always, I am reachable as stack at ctrl-c.club if you have something useful to say.

P.S. I should've looked first, as there are many such attempts in the gemisphere:

search geminispace for 'literate'

Although I do like my screenful of code more than what I've seen elsewhere -- it's minimal, independent, and keeps line numbers for compiler error messages. As usual, Omar Polo has thought of it before me with a nice variation on the theme

Omar's take

Index

Home