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
    next:
      print ","
      print B
      B = A + B
      A = B - A
      if B <= 7000
        goto next
    println ",…"


When run, this program produces:

  0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,…

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

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

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

    neg:
      println "error:N<0"

    end:

When run, this program produces:

  8!=40320

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


    # A mere fizzbuzz...
    loop = 1
    next:
      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:

  1,2,Fizz,4,Buzz,Fizz,7,8,Fizz,Buzz,11,Fizz,13,14,FizzBuzz,16,17,Fizz,19,
  Buzz,Fizz,22,23,Fizz,Buzz,26,Fizz,28,29,FizzBuzz,31,32,Fizz,34,Buzz,…

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…

--
Diddymus


  Up to Main Index                              Up to Journal for July, 2022