This is mostly of interest to programming language enthusiasts.
Babble is a toy programming language with Lisp-like syntax and dynamic types. It's based on the architecture described in the articles Tiny scripting engines for everyone and Scripting without scripting, with important improvements such as quoted strings, making it actually usable. While Babble looks like a Lisp or Scheme, it works more like a modern, friendly programming language (influenced by Janet).
It's implemented as a naive AST interpreter, with a minimal number of new types (mainly closures and nested scopes). The AST can be trivially serialized as JSON.
As of 2 February 2022 (see project news), there's a prototype implementation in Python. It should run in any version from 2.7 onward, both stand-alone and as a module. Included files:
This software is free and open source software under the Artistic License 2.0.
expr construct for optional infix arithmetic was planned, but got scrapped due to terrible performance. It's now offered as a separate library.
Try the following lines, either at the Babble prompt or in a file:
; Semicolons at the start of a line make it into a comment. ; Whitespace doesn't matter outside of quoted strings. (print "Hello, world!\n") (println '2 + 3 =' (+ 2 3)) (function double (n) (* $n 2)) (var m 5) (println (double $m)) ; The JS version has (alert), (confirm) and (prompt), but not (quit).
Notes for Lisp users:
(println "Hello, world!") (apply $println "Hello, world!")
A dollar sign sigil denotes variable lookup. Internally,
$a is expanded to
(get a). Otherwise
a is just a literal string (with the exception shown above). As a consequence, this works too, it's just kinda silly:
('print' 'Hello, world\n')
For a literal list, use square brackets:
[a b c]. They're expanded to
(quote a b c).
From a simple benchmark, Babble programs have a 29x overhead versus equivalent Python code. This isn't too bad as interpreters go, and compiling with Cython (see the included makefile) makes Babble 45% faster again.
Python 2.7 appears to be roughly twice as fast as Python 3.x when it comes to math, and otherwise of similar speed. That can influence benchmarks.
More generally, Babble needs a proper lexer and parser, not an improvisation.exer and parser, not an improvisation.