hoosier ee

wholesome midwestern tech/design weblog

Sequential Machine

2016-12-16

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):

  1. function code
  2. state/action table
  3. machine specification
  4. 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:

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

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...