Scripter Status Report

I have now written many dozens of html scrips that all feel very much the same but do quite different things. I wonder, can I say in a few words what I have done in each script and have those words translated into the script that does the same thing?

Recently many are excited about how ChatGPT seems to do this but cannot explain how it does. I'm following a different approach and find that asking my program what it thinks it has done has been helpful as I stumble into this problem without a clear notion of what I am doing or how I will know when I am finished. Let me highlight a few mechanisms that are all bundled on this page:

I've written on that page an idiomatic description of what one particular script does. I've then coded up as regular expressions each phrase I used in the description. In javascript regular expressions one says /w to match a "word character" which are letters, numbers and underscore. When I say (\w+) I am asking to match one or more word characters that are important enough to remember.

These remembered words will become important parts of the script I hope to generate. They will be the "particulars" within the idioms that I hope to automate.

This is my catalog of idioms sufficient to understand just one script description:

/find the (\w+) with link word (\w+)/i, /then do (\w+) for each/i, /split (\w+) into (\w+) and (\w+) link/i, /then split (\w+) as a (\w+) (\w+)/i, /for each (\w+) do (\w+)/i, /then (\w+) each in (\w+)/i, /then (\w+) layout/i, /use (\w+) (\w+) of each (\w+) as (\w+)/i, /use (\w+) as (\w+)/i, /in (\w+)/i, /fetch ([\w-]+)/i, /with (\w+) ending (\w+)/i, /(\w+) and check it/i, /(\w+) when (\w+) button pressed/i

Regular expression traditions suggest inclosing the text to be matched with forward slashes (/). The trailing letter i indicates that the capitalization of words should be ignored. I expect to write some sort of "code generator" for each of these idioms. But before I start debugging these I thought I would look for simpler mistakes.

I have fond many mistakes by just checking that I am using words matched by (\w+) consistently. I have done this by constructing a graphviz diagram. I've used gold nodes to show things to be done, numbered #2 through #5 in my earlier analysis. I use blue to show idioms I have given names, something like to (blue) blah blah blah. Some of the blah blah will be picked up and saved. I show them in green. The rest are just there to complete an expression in English.

digraph { rankdir=LR; node [shape=box style=filled fillcolor=gold]; "input" "parse" "survey" "lineup" "page" "finish" "cells" "grid" node [fillcolor=lightblue] "#2" "#3" "#4" "#5" node [fillcolor=palegreen] "#2" -> {"input"} "#3" -> {"survey"} "#4" -> {"lineup", "preview"} "#5" -> {"finish"} "input" -> {"paragraphs", "lineup", "parse"} "parse" -> {"paragraph", "text", "external", "link", "lineup", "url"} "survey" -> {"image-caption-survey", "slug", "photos"} "lineup" -> {"input", "page", "open", "row", "row"} "page" -> {"first", "word", "slug", "title", "text", "paragraph", "story"} "finish" -> {"input", "cells", "grid"} "cells" -> {} "grid" -> {} }

My work here continues but I will stop briefly here to relate this work with other well established approaches to bundling and sharing computer programming techniques. Notable techniques include function libraries, programming language compilers, and, close to my heart, pattern languages of programming.

When I identify an idiom with a (\w+) parameter or two I expect a few lines of traditional code will be written in its place. A function library works similarly. When I say Math.sin(angle) I am calling forth the trigonometric function from the Math library and passing in some angle that is relevant for my problem in the moment. I have to remember the name of the function and what is expected of the arguments.

I can remember being confused by the trigonometric function Math.atan2, a name that goes back to the days of Fortran. The function expects a ratio. The digit 2 in the name indicates that both numerator and denominator will be passed to the function and the function will interpret these numbers as a ratio. Why does it do this? Because important trigonometric information will be lost if the ratio, the result of a division, were the only value passed into atan.

We can attach much more meaning to a sequence of words if we apply grammatical rules. Compiler designers assemble elaborate networks of rules and can infer much from their particular assembly. Computer programmers learn how to progress in the back and forth coaxing a compiler to apply the right rules in the right order. It helps to think like a compiler. But this alone makes programing frustrating to someone wanting only an occasional expression of intention to guide automation.

Now imagine that each of the many dozens of scripts written every month each do two or three interesting things in the way they interact with wiki. This may well be the case for two reasons: first, wiki holds the inputs and outputs for scripts and we all use the same wiki. Second, wiki scripts need not implement organizing and sharing mechanisms because these are already available and ready to be used in wiki. Imagine further that with each new script we list the idioms in use to make them do what they do.

There will be variety, of course. And there will be recurring themes. But lets say there are a dozen functional areas in common use, and that a dozen idioms capture the breadth of any one functional area. This means 12 x 12 = 144 recognizable statements assembled in groups of 24 to 36 variations might be enough to provide a plain talk way of automating wiki. We can imagine these being easy to use. But they might just be easy to make, which is not true for either standard libraries or programming language compilers.

A dozen catalogs of idiomatic expressions is substantially more knowable than a large-language-model trained on every fragment of code encountered on the internet. If I told you I created a useful script using nine idioms drawn from three catalogs, each with a dozen forms, you are then presented with 36 things you might desire to learn. If instead I said that my "copilot" wrote the code with a couple dozen tokens of prompt and maybe a trillion nodes in its model. Where do you start?