Nova: Multiset Rewriting Language

I was just reading @natecull’s post in Capabilities & Effects and it sounded so much like a description of Nova, and since there isn’t much overlap between this place and the catlang/rewrite language communities, I figured some folks on here might enjoy watching Wryl’s presentation on Nova, a rewriting language with a very simple core that holds a fantastically comfy UX to program in, to extend, to communicate with over a wire, take dynamic notes in, etc…

https://www.youtube.com/live/OfnEfFb8yks?si=ym_7hTF6UU0KzJAe&t=6315

Quick & Dirty Primer

Vera(a subset of Nova) is a multiset rewriting system designed to converse with computers, created by the same author as Modal. A program is made entirely of facts and rules:

|| The first character in a file assigns a spacer glyph.
|| A program is made of rules and facts.

|| Two spacers indicate the creation of facts
|| Facts are separated by commas, a matchbox, a log, paper

| A rule has a left side | And a right side.
| Facts on the left side | are replaced by facts in the right side

| a flame, a log | a warm fire
| a matchbox | a match, a match a box
| a match, paper | a flame

Spacer

The first character in a file assigns a spacer glyph to be used to indicate rules and facts, the pipe character | is most commonly used:

| this is a rule |
|| this is a fact, this is another fact

Facts

A fact is the name for an item in the bag, the bag is the collection of all existing facts. A line starting with two spacing characters(also called an empty rule) will add facts to the bag, facts are comma separated:

|| a fact, another fact
|| one more fact,
	yet another,
	a last fact

Whitespace only exists to separate the words in a fact, but are not significant when matching facts. These 3 facts are equal:

|| a new fact, a   new fact, a new   fact

Multiple instances of the same facts can be created by using the colon character. There are same amount of instances of these two facts:

|| a, a, a, a, b:4

Rules

A rule is made of a left and often a right side, and indicate facts to remove and replace in the bag.

| a fact, another fact | the result
| another rule | another result
| a rule may not have a right side | 

Evaluation

In turn, each rule is matched against the existing facts found in the bag, starting from the first rule, when a rule’s left-hand side is found in the bag, these facts are replaced by the rule’s right-hand side, and matching is started again from the top.

|flour, sugar, apples| apple cake
|apples, oranges, cherries| fruit salad
|fruit salad, apple cake| fruit cake

|| sugar, oranges, apples, apples, cherries, flour

Vera will match any amount found in the left-hand side, the following two rules are equivalent in Vera:

| an apple, hunger | a core
| an apple, an apple, an apple, hunger | a core

Comments

Vera will discard a rule when all the facts found in its left-hand side are not present in any rule’s right-hand side or declared as facts.

| yellow | This is a comment.
| purple | This is not a comment.
| # | This is also a comment.
|| purple

I’m not going to cover IO, but before someone asks, it can. There’s a whole bunch of implementations around, but since the core is so small, instead of linking you some implementations, I’d suggest trying to make your own, it’s at most 200 lines of C.

8 Likes