Tree @master (Download .tar.gz)
Samovar
Version 0.6 | Entry @ catseye.tc | See also: The League of Extraordinarily Dull Gentlemen ∘ The Swallows

Samovar is a domain-specific language (DSL) for modelling a world using propositions (facts), and possible events that can occur based on those facts, changing them.
Here is a short example of a Samovar description:
scenario IgnatzWithBrick {
[actor(?A),item(?I),~holding(?A,?I)] ?A picks up the ?I. [holding(?A,?I)]
[actor(?A),item(?I),holding(?A,?I)] ?A puts down the ?I. [~holding(?A,?I)]
actor(Ignatz).
item(brick).
goal [].
}
And an implementation of Samovar could take this scenario and use it to, among other things, generate textual descriptions of chains of events like
Ignatz picks up the brick. Ignatz puts down the brick.
Of course, this is a very simple example. (It doesn't even prevent two actors from picking up the same item at the same time!) For more complex examples, and a fuller description of the language, see doc/Samovar.md, which also serves as a test suite.
Implementation
The reference implementation of Samovar, samovar, is written in Python.
It can run under either Python 2.7 or Python 3.x (tested with 3.5 or higher.)
Discussion
This looks like logic programming but the internals are actually much simpler, and what it's doing is not logical inference.
The internals are far simpler than an inference engine or a theorem prover: there are no logical rules in the database, only propositions, so they can be selected by simple pattern-matching rather than full unification.
I originally described it as an "assertion-retraction engine", which could be thought of as a highly stylized form of Prolog programming. Alternately, it could be thought of as assigning preconditions and postconditions, like in Hoare logic, to actions in a world-model. Instead of constructing a proof, though, we simply chain actions together, by selecting any next one whose preconditions hold, and altering the world so that its postconditions hold.
In (I think) autumn 2019, I came across the concept of a production system, and I realized that is basically what Samovar implements. Researching it further, I discovered CLIPS, a production system built in 1985, and I realized that Samovar is not essentially different from an inefficiently-implemented, stripped-down version of CLIPS.
The main innovation in Samovar is the ability to "narrate" the choices the production system makes, with human-readable text.
This isn't too surprising, since my goal with Samovar was to make an expressive language, a syntax in which the author could write a story generator without the undue effort of switching context between prose and code. Picking logical propositions for the "code" and placing them before and after each fragment of prose was a reasonably "ergonomic" choice, and happens to coincide with the structure of a production system.
TODO
- Maybe allow variables to be notated so that they can bind reflexively,
e.g.
?*A looks at ?*Bcan bind both variables to Alice. - Make
?_work such that you can say¬holding(?_, club)to mean "if no one is holding the club".
Commit History
@master
git clone https://git.catseye.tc/Samovar/
- Merge branch 'develop-0.2' of https://github.com/catseye/Samovar into propositions-query Chris Pressey 7 years ago
- Merge pull request #6 from catseye/new-grammar-idea Chris Pressey (commit: GitHub) 7 years ago
- Add --profile option. Chris Pressey 7 years ago
- Knock off a TODO item. Chris Pressey 7 years ago
- Use match_all to find all matches in the database. Seems to work. Chris Pressey 7 years ago
- Implement negative-sense clauses in our pattern matching search. Chris Pressey 7 years ago
- match_all takes a list of Assert's (soon to come: Retract's too.) Chris Pressey 7 years ago
- Make constructor syntax for Term less gratuitously brutal. Chris Pressey 7 years ago
- Implement the basic proposition query w/ recursive pattern matching. Chris Pressey 7 years ago
- Fix up example in README. Chris Pressey 7 years ago
- Generator simulates all and only the scenarios that have a goal. Chris Pressey 7 years ago
- Merge pull request #4 from catseye/unit-tests Chris Pressey (commit: GitHub) 7 years ago
- Merge pull request #5 from catseye/immutable-envs-in-match Chris Pressey (commit: GitHub) 7 years ago
- Allow scenarios to import other preceding scenarios. Chris Pressey 7 years ago
- Add some TODO items. Chris Pressey 7 years ago
- Update the syntax used in other places. Remove obsolete examples. Chris Pressey 7 years ago
- Take the overall grammar of the language in a differen direction. Chris Pressey 7 years ago
- Make Term.match() return the unifier instead of modifying the env. Chris Pressey 7 years ago
- Add two more unit tests, suggesting something we want to change. Chris Pressey 7 years ago
- Some of these methods are unused. Chris Pressey 7 years ago
- Begin adding a unit test suite to test the internals. Chris Pressey 7 years ago
- Merge pull request #3 from catseye/remove-functions Chris Pressey (commit: GitHub) 7 years ago
- Implement ?Var syntax for variables, convert TODO to test case. Chris Pressey 7 years ago
- Merge branch 'develop-0.2' of https://github.com/catseye/Samovar into remove-functions Chris Pressey 7 years ago
- Merge pull request #2 from catseye/syntax-reformation Chris Pressey (commit: GitHub) 7 years ago
- Update test case. Chris Pressey 7 years ago
- Merge branch 'develop-0.2' of https://github.com/catseye/Samovar into syntax-reformation Chris Pressey 7 years ago
- Merge pull request #1 from catseye/add-tests Chris Pressey (commit: GitHub) 7 years ago
- Remove support for functions, as I've concluded they're unneeded. Chris Pressey 7 years ago
- Support for new lexical forms (logic symbols and variable names). Chris Pressey 7 years ago