Sequential Machine

One of the more intimidating constructs available as a J primitive is the dyad ;:, also known as Sequential Machine. This is kind of an oddball compared to the rest of J's primitives.

Instead of taking a regular array as its left argument, it takes a boxed list of several different things (paraphrased):

  • function code
  • state/action table
  • machine specification
  • control flags

Perl-compatible regular expression verbs are part of the standard library, so why does J provide similar functionality? One reason might be flexibility: sequential machine, unlike regex, can be used on arrays of any type (not just strings). However, I suspect the real reason is that J's authors feel that regex is a superfluous thing, and only include it based on popular demand.

Goal

Write a script which transforms (my preferred subset of) Markdown into HTML, and bundle it with my static site generator which builds this website. Note that writing the script is the main goal, as there are plenty of Markdown-to-HTML conversion tools already.

First I found the most-used tags on my site:

count tag name
149 a
100 p
100 div
36 li
33 meta
32 h
28 code
22 script
22 link
22 aside
13 em
11 title
11 span
11 noscript
11 main
11 html
11 header
11 head
11 footer
11 body
9 i
7 kbd
7 br
6 ul
6 pre
5 img
4 ol
4 blockquote

This gave me a starting point for which tags would benefit most from more ergonomic markup.

Some of it is noise (html/head/body tags are auto-generated), but there are some good candidates for automation up at the top, especially link and paragraph tags.

Step 1: links

To begin, I will first write a sed-like script which only replaces [text](href)-style Markdown links with their respective HTML. The first pass will use regex since I'm much more comfortable with that syntax, and the second pass will use ;:. To be continued…