Reintent

@reintent/lib/vocab

A vocabulary for a choice: its possibilities, the words that say each, and what each means to the host (its data).

The core needs none of it; the libraries that talk with a person or a model do: a sentence is read against the words, a model is shown the labels, the host draws the data.

const Size = vocab({
  usual:  { label: '寻常', words: ['正常'], hatScale: 1 },
  absurd: { label: '大得离谱', words: ['离谱'], hatScale: 1.95 },
}, { ordered: true });

// in a component (a read by identity, not by call order: it may sit under an `if`):
const hat = Size.read('hat', { of: 'man', label: '帽子有多大', aka: ['帽子'], default: 'big', ask: true });
hat.kind   // what the evaluation goes on
hat.hatScale // data for the host, directly in λ

A reprogramming that adds a possibility writes a new vocabulary (Size.extend({ … })) into a new program: kinds are the program's, and only a reprogramming changes them (0007 R1).

Interfaces

About

Defined in: packages/lib/src/vocab.ts

What ChoiceRead.about holds for a choice read through a vocabulary.

Properties

PropertyTypeDescription
akareadonly string[]Words that name the choice itself ("帽子").
gesture?GestureThe drag that reaches it (@reintent/lib/gesture).
kindsRecord<string, Omit<KindAbout, "data">>-
label?string-
lessreadonly string[]-
morereadonly string[]Words for a step along an ordered choice.
orderedboolean-
thing?objectThe thing it is a choice of, and its words ("他").
thing.akareadonly string[]-
thing.label?string-
view?readonly string[]What it moves in the picture: the view's paths (man.hat, wardrobe.door.right).

KindAbout

Defined in: packages/lib/src/vocab.ts

Type Parameters

Type ParameterDefault type
Dunknown

Properties

PropertyType
dataD
labelstring
wordsreadonly string[]

Vocab

Defined in: packages/lib/src/vocab.ts

Type Parameters

Type Parameter
K extends string
D

Properties

PropertyType
kindsreadonly K[]
lessreadonly string[]
morereadonly string[]
orderedboolean
tableRecord<K, KindAbout<D>>

Methods

about()
about(name, opts?): About;

Defined in: packages/lib/src/vocab.ts

Human-readable metadata for a choice, without its host data.

Parameters
ParameterType
namestring
opts?AboutOptions<K>
Returns

About

choices()
choices(): Choices<Value<K, D>>;

Defined in: packages/lib/src/vocab.ts

The possibilities, equally weighted.

Returns

Choices<Value<K, D>>

decl()
decl<O>(opts?): VocabDecl<K, D> & { readonly [k in "given" | "applies" | "forbid"]: O[k] };

Defined in: packages/lib/src/vocab.ts

The choice as a field of an entity's declaration (0015): the same possibilities, words and question as read with these options, so a sentence is recognized the same way. What only a read says (of, ask, otherwise, uses) is said where it is read.

Type Parameters
Type ParameterDefault type
O extends DeclOptions<K>Record<never, never>
Parameters
ParameterType
opts?O
Returns

VocabDecl<K, D> & { readonly [k in "given" | "applies" | "forbid"]: O[k] }

extend()
extend<S>(more): Vocab<K | keyof S & string, D>;

Defined in: packages/lib/src/vocab.ts

The vocabulary with possibilities more, after the last (what a reprogramming writes).

Type Parameters
Type Parameter
S extends Record<string, KindSpec>
Parameters
ParameterType
moreS
Returns

Vocab<K | keyof S & string, D>

read()
read(name, opts): Value<K, D>;

Defined in: packages/lib/src/vocab.ts

Read the choice { of, name } with this vocabulary.

Parameters
ParameterType
namestring
optsReadOptions<K>
Returns

Value<K, D>

Type Aliases

AboutOptions

type AboutOptions<K> = Pick<ReadOptions<K>, "label" | "aka" | "thing" | "gesture" | "view">;

Defined in: packages/lib/src/vocab.ts

What a vocabulary puts into a choice's about, besides its possibilities' words.

Type Parameters

Type Parameter
K extends string

DeclOptions

type DeclOptions<K> = AboutOptions<K> & object;

Defined in: packages/lib/src/vocab.ts

A choice declared with a vocabulary (0015): what read takes, less what only a read says.

Type Declaration

NameTypeDescription
applies?Condition-
default?K-
forbid?readonly object[]-
given?readonly string[]-
judge?string | falseThe question System One is asked (default: the label, as read); false: not judged.
prior?Partial<Record<K, number>>-

Type Parameters

Type Parameter
K extends string

KindSpec

type KindSpec = object & Record<string, unknown>;

Defined in: packages/lib/src/vocab.ts

Type Declaration

NameType
label?string
words?readonly string[]

ReadOptions

type ReadOptions<K> = object;

Defined in: packages/lib/src/vocab.ts

Type Parameters

Type Parameter
K extends string

Properties

PropertyTypeDescription
aka?readonly string[]-
ask?booleanAsks a person while unresolved, after System One when it is judged (ask: ['human']).
defaultK-
gesture?GestureThe drag that reaches it, into about (@reintent/lib/gesture).
judge?string | falseThe question System One is asked (default: the label); false: not judged.
label?string-
ofstring-
open?boolean-
otherwise?OtherwiseDeprecated Say what to do when it cannot settle with an enclosing <World onUnresolved> (0046).
thing?About["thing"]-
uses?Record<string, unknown>What System One reads (0008 §8).
view?readonly string[]What it moves in the picture, into about: the view's paths.

Value

type Value<K, D> = K extends string ? object & D : never;

Defined in: packages/lib/src/vocab.ts

A possibility's tag and host data, taken from the current vocabulary.

Type Parameters

Type Parameter
K extends string
D

VocabDecl

type VocabDecl<K, D> = object;

Defined in: packages/lib/src/vocab.ts

A vocabulary's choice as a declaration's field: its kinds with their data, its words in about.

Type Parameters

Type Parameter
K extends string
D

Properties

PropertyModifierType
aboutreadonlyJson
applies?readonlyCondition
default?readonlyK
forbid?readonlyreadonly object[]
given?readonlyreadonly string[]
judge?readonlystring
kindsreadonly{ readonly [k in K]: D }
prior?readonlyobject

Variables

LESS

const LESS: readonly string[];

Defined in: packages/lib/src/vocab.ts


MORE

const MORE: readonly string[];

Defined in: packages/lib/src/vocab.ts

The words for a step along any ordered choice that names none of its own.

Functions

half()

function half(
   label, 
   locale, 
   fallback?
): string;

Defined in: packages/lib/src/vocab.ts

A label in a reader's language, from a bilingual one ("床头 · the bed's head").

Parameters

ParameterTypeDefault value
labelstring | undefinedundefined
localeLangundefined
fallbackstring''

Returns

string


kindAbout()

function kindAbout(r, kind): Omit<KindAbout<unknown>, "data"> | undefined;

Defined in: packages/lib/src/vocab.ts

A possibility of a choice as its read knows it.

Parameters

ParameterType
rChoiceRead
kindunknown

Returns

Omit<KindAbout<unknown>, "data"> | undefined


vocab()

function vocab<S>(spec, opts?): Vocab<keyof S & string, Data<S>>;

Defined in: packages/lib/src/vocab.ts

A possibility's value is { kind, ...data }, its name as its tag. Data with a kind of its own throws: it would hide the tag.

Type Parameters

Type Parameter
S extends Record<string, KindSpec>

Parameters

ParameterType
specS
optsOpts

Returns

Vocab<keyof S & string, Data<S>>

Example

import { createIntent, host, type HostNode } from '@reintent/core';
import { vocab } from '@reintent/lib/vocab';

// Each possibility: a label, the words that say it, and what it means to the host.
const Size = vocab(
  {
    small: { label: 'small', words: ['small', 'little'], scale: 0.8 },
    usual: { label: 'usual', words: ['usual', 'normal'], scale: 1 },
    big: { label: 'big', words: ['big', 'large'], scale: 1.5 },
  },
  { ordered: true },
);

function Man() {
  const hat = Size.read('hat', {
    of: 'man',
    label: 'the hat',
    aka: ['hat'],
    default: 'usual',
    judge: false,
  });
  return host('man', { hat });
}

const intent = createIntent({ program: <Man /> });
intent.decide({ of: 'man', name: 'hat' }, 'big');
const man = intent.realize().tree as HostNode;
console.log(man.props.hat); // → { kind: 'big', scale: 1.5 }

Last updated on

Edit on GitHub