What was said
Keep a person's words beside the program, each stretch bound to the choice it is about, and keep the two in step.
Sam started with a sentence: “A warm card for Grandma”. System Two wrote the card from it. The sentence stays on the screen above the card, and Sam keeps working on both. Picking funny in Choices should change “warm” in the sentence, and rewording “warm” in the sentence should change the card. For that, each stretch of the words has to know which choice it is about.
You will learn
- How
bindties stretches of a sentence to choices - How
statuscompares a stretch with its choice, andfollowrewrites the words to match - How
readEditandreadWordsread an edit to the words
Binding the words
The card, declared as an entity, and the sentence it came from:
import { createIntent, entity, host, useChoose } from '@reintent/core';
import { bind, textOf } from '@reintent/language/said';
import { vocab } from '@reintent/lib/vocab';
const Tone = vocab({
warm: { label: 'warm', words: ['warm', 'cosy'] },
funny: { label: 'funny', words: ['funny', 'a joke'] },
formal: { label: 'formal', words: ['formal', 'proper'] },
});
const card = entity('card', {
tone: Tone.decl({ label: 'the tone', aka: ['tone'], default: 'warm', judge: false }),
});
const Card = card(function Card() {
return host('card', { tone: useChoose(card.tone).kind });
});
const intent = createIntent({ program: <Card /> });
const said = bind('A warm card for Grandma', [
['warm', 'card', 'tone', 'warm'],
['card', 'card'],
]);
said.spans.map((s) => textOf(said, s)); // ['warm', 'card']bind(prompt, bindings) gives a Said: the prompt and its spans. Each Binding is [words, of, name?, kind?], in reading order: the words, the thing, the choice of it, and the possibility they say. A model writes them with its answer, and bind finds each after the one before. A Span keeps the offsets, from and to, with the thing, the choice and the possibility, who bound it (by), and an id (w1, w2…). textOf(said, span) gives its words, and idOf(span) the choice it is bound to, { of: 'card', name: 'tone' }, or undefined for words that name only a thing. A span a model bound is its reading of the words: the host shows it and checks it against what is read, and never writes it as Sam's decision. A decision comes from Sam's own words read by rule, or from Sam's answer to a question.
The binding points at a choice's identity and a possibility's tag, never at a place in a program. It is data beside the intent, kept with the program's version, and it outlives a reprogramming.
Where a span stands
import { follow, status } from '@reintent/language/said';
const [warm, cardWords] = said.spans;
status(warm, intent.realize().reads); // 'agrees'
status(cardWords, intent.realize().reads); // 'names'
intent.decide(card.tone(), 'funny'); // Sam picks funny in Choices
status(warm, intent.realize().reads); // 'differs'
follow(said, intent.realize().reads).prompt; // 'A funny card for Grandma'status(span, reads) compares a span with what an evaluation read. The SpanStatus is one of:
| status | the span |
|---|---|
names | names a thing or a choice, and says no possibility |
agrees | says the possibility the choice is on now |
differs | says one possibility, and the choice is on another |
unread | was reworded, and nothing has read the new words yet |
orphan | points at a choice no read has, after a reprogramming took it |
A panel can underline the words that differ. follow(said, reads) rewrites them instead: every span that says a possibility its choice is no longer on says the current one. wordsFor(read, kind, prompt) picks the words, the possibility's first word in the prompt's script, else its label. Spans that only name a thing stay as they are.
A reprogramming that takes the tone away (a card with a poem, and no tone) leaves the span on “warm” bound to nothing. orphans(said, reads) lists such spans, like a decision nothing reads.
Editing the words
Sam changes “warm” to “cosy”:
import { readEdit, readWords } from '@reintent/language/said';
const { said: next, edit } = readEdit(said, 'A cosy card for Grandma');
edit; // { kind: 'reword', span: { id: 'w1', from: 2, to: 6, …, unread: true, by: 'human' }, text: 'cosy', old: 'warm' }
const [tone] = intent.realize().reads;
readWords(tone, 'cosy'); // { kind: 'warm' }readEdit(said, next) finds the stretch that changed, moves the spans after it, and says what the edit means as a WordEdit:
reword: a span's words changed. The span now covers the new words, markedunreadand bound by the person.unsay: a span's words are gone (“A card for Grandma”).insert: words added outside every span (“A warm card for Grandma, with a joke”).none: nothing changed.
readWords(read, text) reads new words for one choice: the possibility they name, the longest word that appears winning, or null. On an ordered choice, words that name no possibility can still take a step, { dir: 1 } or { dir: -1 }: the vocabulary's own step words first, then the shared ones, FURTHER (“even”, “more”, “更”…) and BACK (“slightly”, “less”, “稍”…). The title's size reads “slightly” as { dir: -1 }. Words and sentences turns these into one event: a decision, a question, or a reprogramming.
Binding more words
A model's answer can say where its new things are said. rebind(said, bindings) applies bindings to words already there: a span with exactly these words is bound again, and otherwise the first stretch of them that no span holds becomes a new span:
import { rebind } from '@reintent/language/said';
const more = rebind(
{ prompt: 'A warm card for Grandma, with a joke', spans: said.spans },
[['a joke', 'card', 'tone', 'funny']],
);
more.spans.map((s) => s.id); // ['w1', 'w2', 'w3']To add a span by hand, nextId(said) gives an id no span has, and withSpan(spans, span) puts it in order, replacing any it overlaps. rewrite(said, id, text) replaces one span's words and shifts every span after it.
Recap
bind(prompt, bindings)ties stretches of what was said to a thing, a choice and a possibility; the spans point at identities, so they outlive a reprogramming.status(span, reads)says whether a span names, agrees, differs, is unread, or is an orphan;followrewrites the words to say what the choices are now.readEdit(said, next)reads an edit as a reword, an unsay or an insert;readWordsreads new words as a possibility or a step.rebind,nextId,withSpanandreprogramkeep the spans in step as the words grow.
Last updated on
Edit on GitHub