A relation that rules invent rows of is derived in full, as an aggregated relation is, and so is a relation derived together with one because an equality rule reads it. A goal-directed query gives the same answers.
exists in a rule head says the head holds for values nobody has given, and the rule invents them: ["rule", ["exists", ["?m"], ["mother", "?c", "?m"]], ["person", "?c"]] gives every person a mother. A rule invents only for an answer whose head does not hold already, so with ["mother", "ada", "eve"] it invents nothing for ada. Rules that invent wait until every rule that invents nothing has finished; then every rule that invents, and whose head does not hold, invents, all at once; the other rules run on what was invented; and so on until nothing more is invented. So the result does not depend on the order rules or facts were added in. A rule that invents cannot aggregate: ... both aggregates and lists variables in "exists". A rule that invents values cannot aggregate.
A rule head can be an and of relation calls, which adds a row to each: ["rule", ["and", ["p", "?x"], ["q", "?x"]], ["r", "?x"]]. Under exists, one unknown is in every row: ["exists", ["?m"], ["and", ["mother", "?c", "?m"], ["female", "?m"]]].
["exists", ["?m", ...], goal] is also a goal: it holds when the goal holds for some value of each listed variable. The listed variables are its own wherever it stands, as a question's own variables are, and never appear in an answer. It is a question, so in plain code ["exists", ["?y"], ["=", "?y", 1]] is true, and it works in a query, a rule body, under not, in find, as a value, and in an invariant.
The README says what Lion does where the research model found it said otherwise. A cond condition counts as false when it is false, null, 0, or "", as the reference's truthiness rule already said, where the README said every string counts as true. A question in plain code is asked as soon as something needs its value, and a program or begin whose value is a goal gives the goal as written, so ["exists", ["?y"], ["=", "?y", 1]] is true as a value, as in ["value/identity", …], and not as a program; the reference says the same. The empty array [] evaluates to itself. The editor section no longer describes the outline, inspector, and source views it lost, its command is turbo dev --filter=@lionlang/repl, and the link to the agent's program no longer points into a local folder. AGENTS.md says bun run test, and packages/examples/CLAUDE.md says the tests use Vitest, as AGENTS.md does.
An invented value is an unknown, written ["some", "?m", ["mother", "ben", "?m"]]: the value ?m stands for in a row ["mother", "ben", ?m]. The form is ordinary Lion, and evaluating it gives the same unknown, so a program can write one, put it in a fact (["fact", ["tall", ["some", "?m", ["mother", "ben", "?m"]]]]), compare it, or look it up. Inside a rule, query, or find, some waits for the variables the rule binds, and every other variable of its goal is its own. With several variables in exists, each gets its own unknown, and its some mentions the others.
Facts may only contain JSON data, but ... is now Facts may only contain data, but ..., since a fact can hold an unknown. The rest of the message is unchanged. The other messages about a value that cannot be a row or an answer, such as The query produced an answer that is not data, say "data" too.
A fact or retract can hold exists: ["fact", ["exists", ["?m"], ["mother", "ben", "?m"]]] adds the row with ben's unknown mother in it, the very row the rule above would invent. why takes one too.
A fact states rows, so it adds the row whether or not the head holds already.
and an aggregate of a list in the head of a rule that invents, since a rule that invents cannot aggregate.
A key makes unknowns equal. When two rows of a keyed relation have the same key and differ only where one holds an unknown that a rule of the keyed relation, or of a relation in a recursive cycle with it, invented, the unknown takes the other row's value: a given value, or, when both are such unknowns, the one that sorts first. With {"key": "child"} on mother, "everyone has a mother" and "twins share a mother" give twins ben and cy the one unknown mother ["some", "?m", ["mother", "ben", "?m"]]. Two different given values are still an error, with the key's message, and an unknown that a fact holds is given, so a key never changes it. An unknown never takes a value that describes it, so of two invented unknowns where one describes the other, the one that describes takes the other.
An unknown is data, as a string is: rows, facts, answers, finds, and aggregates hold it. It equals itself and nothing else, and two unknowns are the same when they are written the same way. It sorts after every record, and unknowns sort by how they are written. A function that needs a number or a string fails on one, as it does on any value of the wrong kind. Lion stays closed-world: ["not", ["=", "?m", "eve"]] holds for ben's unknown mother.
The research and reasoning skills quote the new fact message, and the research skill's engine is rebuilt with this core.
The check that evaluation finishes is weak acyclicity, one rule for computed and invented values. Values flow from the columns a rule's body reads to the columns of its head, and a rule may make a new value for a column, by computing it or inventing it, as long as that value never flows back, through the rules, into making another. ["rule", ["b", "?x", ["number/add", "?x", 10]], ["a", "?x"]] with ["rule", ["a", "?x"], ["b", "?x", "?y"]] used to be refused, since any computed value in a recursive rule's head was, and is now accepted. Every program accepted before is still accepted. A computed value that flows back is refused with the same message as before. An invented one is refused with Rule [...] invents a value for "?m" in its head while recursing, which may never finish. Invent the value in a rule that does not recurse.
Snapshots write rules with exists heads as written, and unknowns in facts as their some forms, so the CLI's --database file keeps them.
a recursion bug the new properties found while writing (an unknown made equal to one describing it never finished)
Unsafe rule head [...]: ?m never appears in a relation in the body. goes on to say To say the head holds for some value nobody has given, list it in "exists": ["exists", ["?m"], head].
["value/unknown?", x] is true for an unknown, so ["not", ["value/unknown?", "?m"]] keeps only known answers. value/object? is false for one.
why explains a row by an answer that gives it as it is, when one does, so after a key makes unknowns equal every row still rests only on rows explained before it. A row that a rule which invents gives only because a key or an equality rule made its unknown equal to another value ends with a new kind of premise, {"same": [unknown, value]}.
Its body cannot ask a question, such as a goal under not, about the group it runs with.
Equality rules: a rule's head can be ["=", a, b], which says the two are one value whenever the body holds. While Lion derives the relations its body reads, an unknown a rule invented there takes the value on the other side, by the rule keys follow, so ["rule", ["=", "?m1", "?m2"], ["twin", "?a", "?b"], ["mother", "?a", "?m1"], ["mother", "?b", "?m2"]] gives twins one mother. The rule holds as the invariant ["and", goal, ..., ["not", ["=", a, b]]] too, so a rule that does not hold is not added and a change that leaves two different known values under it is refused, in an invariant's words. Lion follows each invented value through the columns of the rules, and the relations of a rule that invents an unknown an equality rule can meet are derived together with every relation the equality rule reads, so the unknown can pass through any number of derived relations first: with ["rule", ["listed", "?c", "?m"], ["mother", "?c", "?m"]], the rule ["rule", ["=", "?m", "?n"], ["listed", "?c", "?m"], ["birth", "?c", "?n"]] makes ben's unknown mother the one his birth record names. A question about those relations, such as a goal under not, would go through recursion, and is refused when the rule is added, whatever the facts, with the message any such question gets: Rule [...] asks about "private", which depends on "listed". A question, such as a goal under "not", cannot go through recursion. A question about columns no invented value reaches is allowed. A head can join relation calls and = with and.
An unknown invented for a relation below that one cannot change any more, and the invariant reports it.
exists goes over relation calls only.
a new column, "equality rule", agrees with plain code in every cell; 3 exceptions, all documented, as before.
An equality rule that no invented value can reach, such as one whose body reads only facts, has nothing to make one, and the invariant keeps it
A query may now derive a whole relation where it used to derive a copy of it, when it knows nothing about it
Goal-directed queries are no longer hundreds of times slower than full evaluation on a large model asked many questions. A goal that knows none of its arguments now reads the relation itself, which the database derives once and keeps for every later query, instead of each query deriving a copy that holds every row anyway; a query that knows an argument of a relation the database already holds in full looks its rows up there; and a rule whose known argument sits inside a record pattern or a schema, such as ["claim", "?c", ["schema/open", {"topic": "?t"}]], runs as written and keeps the rows asked about, instead of scanning claim once for each value asked about. On the research model of Lion's own development, the 37 questions of its page took 36.6 seconds goal-directed and 0.12 seconds in full; they now take 0.11 seconds goal-directed. A host no longer needs new LogicDatabase({ goalDirected: false }) for such a model.
A relation is derived the first time a goal reads it with an answer to extend, in goal-directed and full evaluation alike, so a query never fails on a relation that no answer reaches. With ["rule", ["report", "?t"], ["audit", "?t"], ["broken", "?t"]] and no audit rows, ["query", ["report", "?t"]] gives [] even when deriving broken would fail; it used to derive broken before running the rule, and fail.
Neither strategy fails on a relation that no answer reaches
Every value, sorted, duplicates kept
Called on anything else, it waits for the list its argument turns out to be; a find is the list of what it found.
["string/slice", text, start, end] and ["array/slice", list, start, end] cut a part out of text or a list, as JavaScript's slice does: a negative position counts from the end, a position past either end stops there, and without end the part runs to the end. ["string/slice", "lionlang", 0, 4] is "lion", and the two parts of a cut at any position join back into the whole. Like every library function, each waits for a logic variable and refuses a call with another number of arguments.
The record was backfilled from git. Every entry of the hand-written changelog is tied to the commits that made it, and lands, by ancestry alone, in the release it was written under. The releases of @lionlang/core 0.1.0 and 0.1.1, which had no changelog, have sections now, and 0.2.0 lists the @lionlang/cli package it introduced. The decisions behind Lion's design, from the first commit on, each quote the commit messages they rest on, and every feat and fix commit since the first is recorded.
The project record. history/ keeps Lion's changes, releases, and design decisions as a Lion model of the git history. Entries are plain JSON files; every commit, parent, and tag, and the commit that added each file, are facts; and rules derive the rest, such as the release that shipped each change, which is the oldest release whose commit reaches every commit that made it. CHANGELOG.md and the new DECISIONS.md are written from the record by Lion expressions, with bun run history write. bun run history check fails on a feat or fix commit that no entry records, a quote that is not in the commit message it cites, a breaking change that follows from no decision, a version that does not rise, a tag on the wrong commit, or a page that is not what the record writes, and the tests and CI run it. bun run history ask asks the record anything.
CHANGELOG.md and DECISIONS.md are computed by the Lion expressions in history/outputs.json, and the record's tests fail when either file is not what the record writes
A commit that adds a feature or a fix without an entry fails the check from the next commit on, and in CI, which now fetches the whole history
bun run history check fails on a finding of the model that is not listed in history/research/known.json or accepted with a reason; the record's tests run it, so CI does. bun run history ask asks the model anything, such as ["query", ["reversed", "?topic", "?before", "?after"]] for the decisions the project made one way and later another. A decision in history/decisions/ can carry "claims" quoted from its own words, so the model checks what it settles against every rule and behavior.
A database keeps what it derived when facts change and follows the change through it, so a change costs what it reaches: a row that an answer using a changed row gave is taken out and derived again, through relation goals, goals under not, aggregates, and recursion. With one million facts, adding a fact and asking every group's total again takes 23 milliseconds, where it took 1.6 seconds, and a rule with not takes 8 milliseconds, where it took 1.1 seconds. Answers are the same as before; the order they are found in can differ with the changes a database has seen, so use "order" when it matters.
an unknown that the rules of the group it runs with invented takes the other value, a given one, or of two such unknowns the one that nests fewer unknowns, and of those the one that sorts first.
So the result does not depend on the order rules or facts were added in.
So does a program, or a begin, whose value is a goal: it gives the goal as written.
Relations that are aggregated, computed by an algorithm, or asked about, under not, in a find, or as a value, are derived in full, along with everything they depend on.
A relation that rules invent rows of is derived in full, as an aggregated relation is.
Which invariants are asked never changes whether a change is kept.
Invariants take only the "assert" option, read as written.
Nor does a key change an unknown invented for a relation that the keyed relation only reads.
A record or list with a logic variable in it.
and so does a misspelled name inside a predicate, where any other failure means the value does not fit.
It reads what JSON writes, and also zeros before the digits and "−" as the minus sign.
A lookup on a research page can lead with an answer in words: "answer" is a lambda like its query, the page shows the sentence it gives for what the reader chose, and folds the rows under "Show the evidence". A lookup with more than twelve options is a box that finds them as the reader types, not a long list. page-check.json asks the answer with the example.
A goal that binds through a pattern gives what the same goal gives when another goal has bound its variables first.
A checked model of Lion's development, in history/research/. Every statement each commit made, quoted from its message and diff, what the README, AGENTS.md, and CLAUDE.md say now, the claims of each recorded decision, and what Lion at HEAD does in each probed case are one Lion model, built with the lion-research skill, and the record is part of it. Rules over it find where the project disagrees with itself: rules in force that predict different behavior for one case, behavior that breaks a rule in force, removals and breaking changes in commits that record no decision, figures that do not chain, and docs that do not say what Lion does.
Options are read as written, like a relation's column list.
Relations, goals, and logic variables are ordinary values, so rules and queries use the same JSON syntax as the rest of the language and query results are plain Lion data.
Checks list every feat or fix commit that no entry records, every quote that is not in the commit message it cites, every breaking change that follows from no decision, and every release whose versions do not rise or whose tag points elsewhere
The record runs on the workspace's own @lionlang/core, so a change to Lion that breaks the record's rules fails the tests
A file renamed with nothing else changed keeps the commit that added it
git's renames by likeness are not followed
and on a listed finding the model no longer finds
a new one fails the record's tests until someone decides about it
The research skill's page shows how far it has got. While Lion opens the model, a line under the title says so, then "Working out the answers: 3 of 15" with a bar, and every view shows its questions at once, each with "Working this out from the model…" until it is worked out, the view the reader has open first. It used to stay empty until every view was done.
On a research page, "Query the model" is a link at the end of the last view instead of a tab, so the tabs hold only what the reader came for.
A commit nobody has read yet is listed but does not fail the check.
In the research model, what a rule predicts for a case is what its latest statement naming that case predicts, so a rule reworded to allow a case, as the editor's connector rule was, stops predicting the old behavior.
schema/allOf reports the problems of every schema the value does not fit.
schema/anyOf reports one problem, at the value that fits none of its schemas.
["schema/assert", "?doc", "Order"] as a value in a rule fails the query that runs the rule when a value does not fit.
A predicate that fails, or returns anything but true, does not fit.
A record fits a record with the same keys, with values that fit.
A shape cannot ask the database while it is declared, since a snapshot writes the shape and it has to mean the same when it is loaded.
A shape can name the schemas of its form, but cannot call them: ["Expr", 1] inside the form fails, since Expr has no shape yet.
Evaluating the program into an empty database gives the same answers, so a snapshot is a save file that is also ordinary Lion you can read, edit, diff, and run.
Nothing may compute with one of its own variables; that is an error.
They compare values, so a function in the record is a value there, and not a predicate.
why explains facts with every relation computed in full.
A payoff starts the count again, as patience does in early stopping
it stays in the model with why
The research page check's last entry says how to fix what it lists: Questions the plan names that a choice set aside, or that have readings nobody chose between. This must be empty: reach each through meant, or ask the reader which sense they mean. build-explorer.mjs reminds the agent to run it whenever the plan names questions as records, and the skill says the check must give [].
a change is not kept until both have run on it
The skill tells the agent to fix or drop such a change and never to relax the requirement to let a score count.
The files as they are now have regressed when every run on them is worse than the best.
an answer otherwise rules a direction out
A lion-reasoning score can list what it requires, such as {"question": {"failing tests": "test.mjs"}, "value": 0}: a version where that is unanswered or answered otherwise has no score, and unmet lists it, so a change that breaks the tests never becomes the best. A direction can list what it needs; it waits while that is unanswered or not yet decided by whoever ask names, and is ruled_out once it is answered otherwise, so the user's answer prunes the directions.
A direction or lead can also wait: on a question it needs that only the user may answer (reasoning), or on the reader's choice of a sense of a question it pursues (research)
The lion-reasoning skill keeps the record of an experiment loop, in the manner of autoresearch. Notes declare scores, numbers to make better, such as {"question": {"comparisons": "bench.mjs"}, "better": "lower"}, and directions, the ideas to try; an observation that tries a direction is an experiment of it. What a version is sure to give is its worst run: the best is the best of those, and a version has improved a score when its worst run beats the best that any earlier version was sure to give, so improved, best, score_in, and regressed follow the evidence and not one lucky run; runs of a score that differ are its spread rather than a dispute. A direction pays off when its experiment improves a score, and is set aside after as many misses in a row as its patience, 3 unless it says. The standing question "Where should the next experiment go?" lists the live directions, those that paid off most first.
On an earlier version, it can only keep an improvement or make it larger
The list of where to try next puts the live directions that paid off most first, then those tried least
The skill asks for the same number of runs on each version
The best a score has been is the best of those across versions.
With one run each this is beating the best so far.
Where one is unanswered, or answered otherwise in any run, the version has no score: no range, no best, no improvement.
Runs of a score that differ are its spread, so disputed leaves scores out.
what the version is sure to give is its worst run
why on an improvement ends in the runs it compared and a check such as ["number/lessThan", 62, 117]
The lion-research skill saves its written answer as report.md in the research folder on every run, not only when the user asks for a file, and gives the user the same words. In the skill's eval, one of two runs before the change wrote no report and failed the five checks that read it; both runs after it wrote one.
Disputes do not hold a lead open
a record covers every answered question that has its keys and values
The lion-research skill records leads, the lines of inquiry a research run follows: "leads": [{"id": "outside-warehouses", "statement": "…", "pursues": [{"warehouses": "tarnwell"}], "patience": 2}], and "for": ["outside-warehouses"] on each source read to follow one. A source pays off for a lead when it says something first-hand the lead covers; a lead is done when every question it pursues has an answer two publishers give first-hand, waits while the reader has not chosen a sense of one, and is set aside after as many sources in a row as its patience gave it nothing. The standing questions ask where the next search should go and how each lead ended, and the page's "How solid is it" shows the reader "What was looked for".
Senses the reader set aside are not covered
A question only one publisher can answer never finishes its lead
The research recorder numbers the sources read for leads in the order their notes are recorded
A goal-directed query that knows an argument a rule's head computes by asking a question of its own, such as ["query", ["meant", {"revenue": "t"}, "?q"]] over ["rule", ["base", "?q", ["array/reduce", ["find", "?key", ["reading", "?key"]], "?q", ["lambda", ["rest", "key"], ["object/remove", "rest", "key"]]]], ["answer", "?q", "?_"]] and ["rule", ["meant", "?base", "?q"], ["base", "?q", "?base"]], gives the answers of full evaluation again, instead of failing with an internal error, undefined is not an object (evaluating 'literal.parts'). The rewrite took the find's own ?key for a variable the rule had to bind first. This is the meant relation of the lion-research skill. The rewrite now follows the asking rule wherever it asks what a value needs: a query whose argument is computed by a question with variables of its own, such as ["path", ["array/reduce", ["find", "?a", ["start", "?a"]], 0, ["lambda", ["sum", "a"], ["number/add", "sum", "a"]]], "?to"], now derives only what it reaches, as one that writes the value does.
A commit counts as read when a claim was made by it, so a commit that records its change in history/notes/ is not listed among the commits the model has nothing from.
deciding a question again differently is a reversal the model derives
DECISIONS.md lists every decided question, oldest first, with each answer it was given and the records that explain it, and for each thing a record asserts, whether it holds when Lion is run, is broken, is only stated, or was replaced by a later word.
A probe can answer for a feature as well as a behavior: {"feature": "math/+", "kind": "function", "program": ["value/function?", "math/+"]} gives false, so the record that says math/+ is gone holds. ["lion/special-form?", name] tells a probe whether Lion has a special form of that name. bun run history check reports a feature's probe that gives neither true nor false, and a question two probes answer.
["lion/special-form?", name] says whether Lion has a special form of that name
repo/files gives no paths for a path that names nothing
["repo/files", path] gives the paths of the files under a folder of the repository
A path that leads out of the repository, a path that names no file, and a command the file does not declare each fail
["repo/json", path] gives a JSON file as a value
["repo/read", path] gives the text of a file of the repository
runs a command that history/research/commands.json declares and gives its exit code and what it wrote