User Tools

Site Tools


notes:internals:db

This is an old revision of the document!


Database

Folk's database stores all Wishes, Claims, Whens, and Holds. Essentially, it stores everything that happens in Folk. The database works with Statements, either inserting or removing them. All those verbs I mentioned— Wish, When, etc—are functions that insert a Statement into the database. We'll cover removal later.

So, what is a Statement? A Statement consists of three parts: the Clause, the child matches, and metadata. Let's start with the Clause: a Clause is an array of words, with each word known as a Term. An example Clause, “the sky is blue”, would become [“the”, “sky”, “is”, “blue”]. We'll cover child matches and metadata in a bit.

Let's see what happens when we run Claim.

Claim the sky is blue

When this code runs, it will generate a Clause containing “current-file.folk claims the sky is blue”. Notice there's a part that was prepended to the beginning, “current-file.folk claims”. This tells the database what file this Claim came from, and that it's a Claim, not a Wish. This same thing applies to Wishes, except with “wishes” instead of “claims”.

One other important thing is Whens are also stored in the database. Let's continue with the previous example, except with a When this time:

set foo bar
When the sky is /color/ { # code here }

This will insert the following: “when the sky is /color/ { # code here } with environment {foo bar}”. There's quite a bit happening here, so let's break it down:

  1. We add “when” to the beginning, so the database knows this is a When
  2. We preserve both the query and the code
  3. We add “with environment {foo bar}”, as tcl doesn't capture scopes. We manually capture the scope

instead. We'll use this to execute the When later

notes/internals/db.1757199087.txt.gz · Last modified: 2025/09/06 22:51 by smj-edison

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki