Reintent

Words bound to the picture

The language package keeps what was said beside the program and ties it, through the choices, to the picture.

Sam's card has a sentence above it, “A warm card for Grandma”, and a picture under it. When Sam points at “warm”, the card should show where the tone is in the picture. When Sam taps the card's border in the picture, the sentence should light “warm”. Words, choices and the picture are three places for one thing, and @reintent/language keeps the bindings between them.

You will learn

  • What the language package holds, and what it builds on
  • How chainOf goes from a span, a choice or a place in the picture to the other two
  • How viewsOf, reach, choicesOfSpan and choicesAt make up the chain

The package

@reintent/language has three modules:

ModuleWhat it holds
@reintent/language/saidwhat was said and its spans, each bound to a choice's identity and a possibility
@reintent/language/wordsa sentence, or an edit to the words, read as one event: a decision, a question, a reprogramming, or something said of the whole
@reintent/language/bindingthe chain from words to choices to the picture

It reads @reintent/core's public entry and two libraries: the possibilities' words come from @reintent/lib/vocab, and labels in two languages from @reintent/lib/text. Nothing in @reintent/lib imports it. An intent never needs it: it is for the host, which keeps the words beside the intent.

The chain

A choice says which parts of the picture it moves in its declaration, with view:

import { createIntent, entity, host, useChoose } from '@reintent/core';
import { chainOf } from '@reintent/language/binding';
import { bind } from '@reintent/language/said';
import { vocab } from '@reintent/lib/vocab';

const Tone = vocab({
  warm: { label: 'warm', words: ['warm'] },
  funny: { label: 'funny', words: ['funny'] },
});
const card = entity('card', {
  tone: Tone.decl({ default: 'warm', judge: false, view: ['card.border'] }),
});
const Card = card(function Card() {
  return host('card', { tone: useChoose(card.tone).kind });
});
const { reads } = createIntent({ program: <Card /> }).realize();
const said = bind('A warm card for Grandma', [['warm', 'card', 'tone', 'warm']]);

const fromWords = chainOf(said, reads, { span: 'w1' });
[...fromWords.choices]; // ['card#tone']
[...fromWords.views]; // ['card.border']

const fromPicture = chainOf(said, reads, { view: 'card[front].border' });
[...fromPicture.spans]; // ['w1']

chainOf(said, reads, focus) takes a Focus, what a person points at: a span ({ span: 'w1' }), a choice ({ choice: 'card#tone' }) or a path in the picture ({ view: 'card[front].border' }). It gives a Chain: the span ids, the choice keys and the view paths it is bound to. Nothing pointed at gives NO_CHAIN. A host lights what is in the chain: the words, the rows of choices, the boxes in the picture. The lab UI's words, rows and lines do this.

A fourth argument, shown, says which choices are in the picture now. A dream told in beats shows one beat at a time, and a beat that is not on screen is bound to nothing there.

The pieces

  • viewsOf(read): the view paths a choice moves, its about.view, or else its thing.
  • reach(view, path): how well a view path names a path in the picture: 3 the same part, 2 the same instance, 1 the same thing, 0 not at all. A path is a semantic path, as @reintent/scene names them (Drawing a scene).
  • choicesOfSpan(span, reads): the choices a span is about. A span that names only the thing (“the card”) is about every choice of it.
  • choicesAt(path, reads): the choices whose view reaches a path, the closest only.

Only reads and their about are used, so the chain is the same for a program written in JSX and one read from a declaration.

Recap

  • @reintent/language holds what was said (said), how a sentence or an edit is read (words), and the chain to the picture (binding). It builds on core, lib/vocab and lib/text, and no library imports it.
  • chainOf goes from a span, a choice or a path in the picture to the other two; view in a declaration binds a choice to the picture.
  • viewsOf, reach, choicesOfSpan and choicesAt are the steps of the chain.

Last updated on

Edit on GitHub