Function: bind()
@kortexya/reasoninglayer / bind
Function: bind()
Section titled “Function: bind()”bind<
T>(name,term):T
Defined in: src/builders/psi.ts:151
Name a clause’s own identity, so another clause can refer to the SAME term.
Type Parameters
Section titled “Type Parameters”T extends PsiTermInput
Parameters
Section titled “Parameters”string
The binder, e.g. "?C". Must start with ?.
T
The term the binder names, from psi.
Returns
Section titled “Returns”T
The same term, carrying the binder.
Throws
Section titled “Throws”ValidationError when name does not start with ?.
Remarks
Section titled “Remarks”This is the OSFQL ?C: sort(...) form. Without it a rule can only relate
two clauses through their feature VALUES — “an invoice whose number matches
this payment’s invoice_number”. With it a clause refers to the identity of
the term another clause bound, which is what a rule about a referenced term
needs.
Refer to the bound term from elsewhere in the rule with the plain variable
"?C"; the engine reads the join from the term ids.
A nested term (a feature value, or the clause of not()) keeps its binder
since engine #438, so a nested bind() adds an identity join too.
Only meaningful in an inference context. Term CRUD ignores it.
Example
Section titled “Example”import { bind, psi } from '@kortexya/reasoninglayer';
// "a line whose order is THIS order" — not "an order with the same number"await client.inference.addRule({ term: psi('large_order', { order: '?O' }), antecedents: [ bind('?O', psi('sales_order', { status: 'open' })), psi('order_line', { order: '?O', amount: '?A' }), ],});