Up to Main Index                              Up to Journal for July, 2022

                     JOURNAL FOR SATURDAY 30TH JULY, 2022

SUBJECT: A mere programming language
   DATE: Sat 30 Jul 16:03:12 BST 2022

For some other — non-WolfMUD — work I am doing, a client needs a programming
language. The requirements are it should be: simple, lightweight, extensible
and cross-platform. Programs have to run stand-alone and be embeddable in Go
programs. The last requirement is that using cgo isn’t an option.

Being able to run programs stand-alone means the programs can be tested, with
testing integrated in CI/CD pipelines without knowing Go. Being embedded means
it will be possible to integrate with the Go testing framework for those who
are Go developers.

It’s an interesting project :)

To that end I have been creating Mere as in “a mere programming language”. It
is a very simple language heavily influenced by early BASIC. I’m sure it will
eventually have some interesting features, but that’s the starting point.

It’s only taken a few hours, but I have a proof of concept Mere that can run a
few, nearly interesting, test programs. There is a Fibonacci sequence:

    # A mere Fibonacci sequence...
    A = 0
    B = 1
    print A
      print ","
      print B
      B = A + B
      A = B - A
      if B <= 7000
        goto next
    println ",…"

When run, this program produces:


For…next loops are not implemented yet, but goto is :| At least goto is using
labels and not line numbers! The indentation is cosmetic, white-space has no
significance. Here is a factorial example:

    # A mere factorial...

    # Our input number
    N = 8

    f = 1
    x = 2

    if N < 0
      goto neg
    if N < 2
      goto done

      f = f * x
      x = x ++
      if x <= N
        goto next

      print N
      print "!"
      print "="
      println f
    goto end

      println "error:N<0"


When run, this program produces:


Finally there is an implementation of FizzBuzz, because why not?:

    # A mere fizzbuzz...
    loop = 1
      if loop % 3 == 0
        print "fizz"
      if loop % 5 == 0
        print "buzz"
      if loop % 3 != 0 && loop % 5 != 0
        print loop
      print ","
      loop = loop ++
    if loop <= 35
      goto next
    println "…"

When run, this program produces:


The proof of concept implementation is very ugly, hacky, a little slow and
with few features. I’m now working on an improved, cleaner implementation.

Mere isn’t going to win any awards or take the world by storm. However, I’ve
known for a while that WolfMUD will need some kind of scripting capability in
the zone files. This would allow mobiles/NPCs to react and interact with their
environment and the players more intelligently under the control of the zone
authors. There is a chance that I could make Mere fit that need.

Mere will remain mine, I’ll retain all copyrights and it will be released as
open source. Whether anyone else will be interested in it is another matter…


  Up to Main Index                              Up to Journal for July, 2022