diff --git a/README.md b/README.md index 3e63863..26717fc 100644 --- a/README.md +++ b/README.md @@ -84,10 +84,10 @@ Include the headers from `include/ds/` in your C++ project. ### TypeScript/JavaScript Example ```typescript -import { rule_t, search_t } from "atsds"; +import { Rule, Search } from "atsds"; // Create a search engine -const search = new search_t(1000, 10000); +const search = new Search(1000, 10000); // Modus ponens: P -> Q, P |- Q search.add("(`P -> `Q) `P `Q"); @@ -102,7 +102,7 @@ search.add("(((! `p) -> (! `q)) -> (`q -> `p))"); search.add("(! (! X))"); // Target: X (double negation elimination) -const target = new rule_t("X"); +const target = new Rule("X"); // Execute search until target is found while (true) { @@ -236,8 +236,8 @@ A fact is a rule without premises: Grounding substitutes variables with values using a dictionary: ```typescript -const a = new term_t("`a"); -const dict = new term_t("((`a b))"); // Substitute `a with b +const a = new Term("`a"); +const dict = new Term("((`a b))"); // Substitute `a with b const result = a.ground(dict); console.log(result.toString()); // "b" ``` @@ -248,9 +248,9 @@ Matching unifies the first premise of a rule with a fact to produce a new rule. ```typescript // Modus ponens rule: (p -> q), p |- q -const mp = new rule_t("(`p -> `q)\n`p\n`q\n"); +const mp = new Rule("(`p -> `q)\n`p\n`q\n"); // Double negation elimination axiom: !!x -> x -const pq = new rule_t("((! (! `x)) -> `x)"); +const pq = new Rule("((! (! `x)) -> `x)"); // Match produces: !!x |- x console.log(mp.match(pq).toString()); // "(! (! `x))\n----------\n`x\n" ``` @@ -260,13 +260,13 @@ console.log(mp.match(pq).toString()); // "(! (! `x))\n----------\n`x\n" ### TypeScript/JavaScript - `buffer_size(size?: number)`: Get/set buffer size for internal operations -- `string_t`: String wrapper class -- `variable_t`: Logical variable class -- `item_t`: Item (constant/functor) class -- `list_t`: List class -- `term_t`: General term class (variable, item, or list) -- `rule_t`: Logical rule class -- `search_t`: Search engine for inference +- `String_`: String wrapper class +- `Variable`: Logical variable class +- `Item`: Item (constant/functor) class +- `List`: List class +- `Term`: General term class (variable, item, or list) +- `Rule`: Logical rule class +- `Search`: Search engine for inference ### Python diff --git a/atsds/index.mts b/atsds/index.mts index 69348b2..979241b 100644 --- a/atsds/index.mts +++ b/atsds/index.mts @@ -55,14 +55,14 @@ interface StaticCommon { * Valid initialization arguments for deductive system types. * @internal */ -type InitialArgument = _common_t | T | string | dst.Buffer | null; +type InitialArgument = _Common | T | string | dst.Buffer | null; /** * Base class for all deductive system wrapper types. * Handles initialization, serialization, and common operations. * @internal */ -class _common_t { +class _Common { type: StaticCommon; value: T; capacity: number; @@ -77,7 +77,7 @@ class _common_t { */ constructor(type: StaticCommon, value: InitialArgument, size: number = 0) { this.type = type; - if (value instanceof _common_t) { + if (value instanceof _Common) { this.value = value.value; this.capacity = value.capacity; if (size !== 0) { @@ -162,16 +162,16 @@ class _common_t { * * @example * ```typescript - * const str1 = new string_t("hello"); - * const str2 = new string_t(str1.data()); // From binary + * const str1 = new String_("hello"); + * const str2 = new String_(str1.data()); // From binary * console.log(str1.toString()); // "hello" * ``` */ -export class string_t extends _common_t { +export class String_ extends _Common { /** * Creates a new string instance. * - * @param value - Initial value (string, buffer, or another string_t). + * @param value - Initial value (string, buffer, or another String_). * @param size - Optional buffer capacity for the internal storage. * @throws {Error} If initialization fails. */ @@ -186,15 +186,15 @@ export class string_t extends _common_t { * * @example * ```typescript - * const var1 = new variable_t("`X"); + * const var1 = new Variable("`X"); * console.log(var1.name().toString()); // "X" * ``` */ -export class variable_t extends _common_t { +export class Variable extends _Common { /** * Creates a new variable instance. * - * @param value - Initial value (string, buffer, or another variable_t). + * @param value - Initial value (string, buffer, or another Variable). * @param size - Optional buffer capacity for the internal storage. * @throws {Error} If initialization fails. */ @@ -205,10 +205,10 @@ export class variable_t extends _common_t { /** * Get the name of this variable. * - * @returns The variable name as a string_t. + * @returns The variable name as a String_. */ - name(): string_t { - return new string_t(this.value.name()); + name(): String_ { + return new String_(this.value.name()); } } @@ -218,15 +218,15 @@ export class variable_t extends _common_t { * * @example * ```typescript - * const item = new item_t("atom"); + * const item = new Item("atom"); * console.log(item.name().toString()); // "atom" * ``` */ -export class item_t extends _common_t { +export class Item extends _Common { /** * Creates a new item instance. * - * @param value - Initial value (string, buffer, or another item_t). + * @param value - Initial value (string, buffer, or another Item). * @param size - Optional buffer capacity for the internal storage. * @throws {Error} If initialization fails. */ @@ -237,10 +237,10 @@ export class item_t extends _common_t { /** * Get the name of this item. * - * @returns The item name as a string_t. + * @returns The item name as a String_. */ - name(): string_t { - return new string_t(this.value.name()); + name(): String_ { + return new String_(this.value.name()); } } @@ -250,16 +250,16 @@ export class item_t extends _common_t { * * @example * ```typescript - * const list = new list_t("(a b c)"); + * const list = new List("(a b c)"); * console.log(list.length()); // 3 * console.log(list.getitem(0).toString()); // "a" * ``` */ -export class list_t extends _common_t { +export class List extends _Common { /** * Creates a new list instance. * - * @param value - Initial value (string, buffer, or another list_t). + * @param value - Initial value (string, buffer, or another List). * @param size - Optional buffer capacity for the internal storage. * @throws {Error} If initialization fails. */ @@ -282,8 +282,8 @@ export class list_t extends _common_t { * @param index - The zero-based index of the element. * @returns The term at the specified index. */ - getitem(index: number): term_t { - return new term_t(this.value.getitem(index)); + getitem(index: number): Term { + return new Term(this.value.getitem(index)); } } @@ -293,15 +293,15 @@ export class list_t extends _common_t { * * @example * ```typescript - * const term = new term_t("(f `x a)"); + * const term = new Term("(f `x a)"); * const innerTerm = term.term(); // Get the underlying term type * ``` */ -export class term_t extends _common_t { +export class Term extends _Common { /** * Creates a new term instance. * - * @param value - Initial value (string, buffer, or another term_t). + * @param value - Initial value (string, buffer, or another Term). * @param size - Optional buffer capacity for the internal storage. * @throws {Error} If initialization fails. */ @@ -310,19 +310,19 @@ export class term_t extends _common_t { } /** - * Extracts the underlying term and returns it as its concrete type (variable_t, item_t, or list_t). + * Extracts the underlying term and returns it as its concrete type (Variable, Item, or List). * - * @returns The term as a variable_t, item_t, or list_t. + * @returns The term as a Variable, Item, or List. * @throws {Error} If the term type is unexpected. */ - term(): variable_t | item_t | list_t { + term(): Variable | Item | List { const term_type: dst.TermType = this.value.get_type(); if (term_type === ds.TermType.Variable) { - return new variable_t(this.value.variable()); + return new Variable(this.value.variable()); } else if (term_type === ds.TermType.Item) { - return new item_t(this.value.item()); + return new Item(this.value.item()); } else if (term_type === ds.TermType.List) { - return new list_t(this.value.list()); + return new List(this.value.list()); } else { throw new Error("Unexpected term type."); } @@ -338,23 +338,23 @@ export class term_t extends _common_t { * * @example * ```typescript - * const a = new term_t("`a"); - * const b = new term_t("((`a b))"); + * const a = new Term("`a"); + * const b = new Term("((`a b))"); * console.log(a.ground(b).toString()); // "b" * * // With scope - * const c = new term_t("`a"); - * const d = new term_t("((x y `a `b) (y x `b `c))"); + * const c = new Term("`a"); + * const d = new Term("((x y `a `b) (y x `b `c))"); * console.log(c.ground(d, "x").toString()); // "`c" * ``` */ - ground(other: term_t, scope: string = ""): term_t | null { + ground(other: Term, scope: string = ""): Term | null { const capacity = buffer_size(); const term = ds.Term.ground(this.value, other.value, scope, capacity); if (term === null) { return null; } - return new term_t(term, capacity); + return new Term(term, capacity); } /** @@ -365,21 +365,21 @@ export class term_t extends _common_t { * * @example * ```typescript - * const a = new term_t("`a"); - * const b = new term_t("b"); + * const a = new Term("`a"); + * const b = new Term("b"); * const result = a.match(b); * if (result !== null) { * console.log(result.toString()); // "((1 2 `a b))" * } * ``` */ - match(other: term_t): term_t | null { + match(other: Term): Term | null { const capacity = buffer_size(); const term = ds.Term.match(this.value, other.value, "1", "2", capacity); if (term === null) { return null; } - return new term_t(term, capacity); + return new Term(term, capacity); } /** @@ -392,23 +392,23 @@ export class term_t extends _common_t { * * @example * ```typescript - * const a = new term_t("`x"); - * const b = new term_t("((pre_) (_suf))"); + * const a = new Term("`x"); + * const b = new Term("((pre_) (_suf))"); * console.log(a.rename(b).toString()); // "`pre_x_suf" * * // With empty prefix (only suffix) - * const c = new term_t("`x"); - * const d = new term_t("(() (_suf))"); + * const c = new Term("`x"); + * const d = new Term("(() (_suf))"); * console.log(c.rename(d).toString()); // "`x_suf" * ``` */ - rename(prefix_and_suffix: term_t): term_t | null { + rename(prefix_and_suffix: Term): Term | null { const capacity = buffer_size(); const term = ds.Term.rename(this.value, prefix_and_suffix.value, capacity); if (term === null) { return null; } - return new term_t(term, capacity); + return new Term(term, capacity); } } @@ -418,16 +418,16 @@ export class term_t extends _common_t { * * @example * ```typescript - * const rule = new rule_t("(father `X `Y)\n----------\n(parent `X `Y)\n"); + * const rule = new Rule("(father `X `Y)\n----------\n(parent `X `Y)\n"); * console.log(rule.conclusion().toString()); // "(parent `X `Y)" * console.log(rule.length()); // 1 (number of premises) * ``` */ -export class rule_t extends _common_t { +export class Rule extends _Common { /** * Creates a new rule instance. * - * @param value - Initial value (string, buffer, or another rule_t). + * @param value - Initial value (string, buffer, or another Rule). * @param size - Optional buffer capacity for the internal storage. * @throws {Error} If initialization fails. */ @@ -450,8 +450,8 @@ export class rule_t extends _common_t { * @param index - The zero-based index of the premise. * @returns The premise term at the specified index. */ - getitem(index: number): term_t { - return new term_t(this.value.getitem(index)); + getitem(index: number): Term { + return new Term(this.value.getitem(index)); } /** @@ -459,37 +459,37 @@ export class rule_t extends _common_t { * * @returns The conclusion term. */ - conclusion(): term_t { - return new term_t(this.value.conclusion()); + conclusion(): Term { + return new Term(this.value.conclusion()); } /** * Ground this rule using a dictionary to substitute variables with values. * * @param other - A rule representing a dictionary (list of pairs). Each pair contains a variable and its substitution value. - * Example: new rule_t("((`a b))") means substitute variable `a with value b. + * Example: new Rule("((`a b))") means substitute variable `a with value b. * @param scope - Optional scope string for variable scoping. * @returns The grounded rule, or null if grounding fails. * * @example * ```typescript - * const a = new rule_t("`a"); - * const b = new rule_t("((`a b))"); + * const a = new Rule("`a"); + * const b = new Rule("((`a b))"); * console.log(a.ground(b).toString()); // "----\nb\n" * * // With scope - * const c = new rule_t("`a"); - * const d = new rule_t("((x y `a `b) (y x `b `c))"); + * const c = new Rule("`a"); + * const d = new Rule("((x y `a `b) (y x `b `c))"); * console.log(c.ground(d, "x").toString()); // "----\n`c\n" * ``` */ - ground(other: rule_t, scope: string = ""): rule_t | null { + ground(other: Rule, scope: string = ""): Rule | null { const capacity = buffer_size(); const rule = ds.Rule.ground(this.value, other.value, scope, capacity); if (rule === null) { return null; } - return new rule_t(rule, capacity); + return new Rule(rule, capacity); } /** @@ -502,18 +502,18 @@ export class rule_t extends _common_t { * * @example * ```typescript - * const mp = new rule_t("(`p -> `q)\n`p\n`q\n"); - * const pq = new rule_t("((! (! `x)) -> `x)"); + * const mp = new Rule("(`p -> `q)\n`p\n`q\n"); + * const pq = new Rule("((! (! `x)) -> `x)"); * console.log(mp.match(pq).toString()); // "(! (! `x))\n----------\n`x\n" * ``` */ - match(other: rule_t): rule_t | null { + match(other: Rule): Rule | null { const capacity = buffer_size(); const rule = ds.Rule.match(this.value, other.value, capacity); if (rule === null) { return null; } - return new rule_t(rule, capacity); + return new Rule(rule, capacity); } /** @@ -526,23 +526,23 @@ export class rule_t extends _common_t { * * @example * ```typescript - * const a = new rule_t("`x"); - * const b = new rule_t("((pre_) (_suf))"); + * const a = new Rule("`x"); + * const b = new Rule("((pre_) (_suf))"); * console.log(a.rename(b).toString()); // "----\n`pre_x_suf\n" * * // With empty prefix (only suffix) - * const c = new rule_t("`x"); - * const d = new rule_t("(() (_suf))"); + * const c = new Rule("`x"); + * const d = new Rule("(() (_suf))"); * console.log(c.rename(d).toString()); // "----\n`x_suf\n" * ``` */ - rename(prefix_and_suffix: rule_t): rule_t | null { + rename(prefix_and_suffix: Rule): Rule | null { const capacity = buffer_size(); const rule = ds.Rule.rename(this.value, prefix_and_suffix.value, capacity); if (rule === null) { return null; } - return new rule_t(rule, capacity); + return new Rule(rule, capacity); } } @@ -552,7 +552,7 @@ export class rule_t extends _common_t { * * @example * ```typescript - * const search = new search_t(); + * const search = new Search(); * search.add("(parent john mary)"); * search.add("(father `X `Y)\n----------\n(parent `X `Y)\n"); * search.execute((rule) => { @@ -561,7 +561,7 @@ export class rule_t extends _common_t { * }); * ``` */ -export class search_t { +export class Search { _search: dst.Search; /** @@ -615,9 +615,9 @@ export class search_t { * @param callback - Function called for each candidate rule. Return false to continue, true to stop. * @returns The number of rules processed. */ - execute(callback: (candidate: rule_t) => boolean): number { + execute(callback: (candidate: Rule) => boolean): number { return this._search.execute((candidate: dst.Rule): boolean => { - return callback(new rule_t(candidate).copy()); + return callback(new Rule(candidate).copy()); }); } } diff --git a/docs/api/typescript.md b/docs/api/typescript.md index 6e7e364..ce2a1c5 100644 --- a/docs/api/typescript.md +++ b/docs/api/typescript.md @@ -5,13 +5,13 @@ This page documents the TypeScript API for the `atsds` package. The documentatio ```typescript import { buffer_size, - string_t, - variable_t, - item_t, - list_t, - term_t, - rule_t, - search_t + String_, + Variable, + Item, + List, + Term, + Rule, + Search } from "atsds"; ``` @@ -38,19 +38,19 @@ const oldSize = buffer_size(2048); // Set new size, returns old size --- -## string_t +## String_ Wrapper class for deductive system strings. ### Constructor ```typescript -constructor(value: string | Buffer | string_t, size?: number) +constructor(value: string | Buffer | String_, size?: number) ``` **Parameters:** -- `value`: Initial value (string, buffer, or another string_t) +- `value`: Initial value (string, buffer, or another String_) - `size` (optional): Buffer capacity for internal storage ### Methods @@ -84,7 +84,7 @@ size(): number Create a deep copy of this instance. ```typescript -copy(): string_t +copy(): String_ ``` #### key() @@ -98,94 +98,94 @@ key(): string **Example:** ```typescript -const str1 = new string_t("hello"); -const str2 = new string_t(str1.data()); +const str1 = new String_("hello"); +const str2 = new String_(str1.data()); console.log(str1.toString()); // "hello" ``` --- -## variable_t +## Variable Wrapper class for logical variables in the deductive system. ### Constructor ```typescript -constructor(value: string | Buffer | variable_t, size?: number) +constructor(value: string | Buffer | Variable, size?: number) ``` **Parameters:** -- `value`: Initial value (string starting with backtick, buffer, or another variable_t) +- `value`: Initial value (string starting with backtick, buffer, or another Variable) - `size` (optional): Buffer capacity for internal storage ### Methods -Inherits all methods from `string_t`, plus: +Inherits all methods from `String_`, plus: #### name() Get the name of this variable (without the backtick prefix). ```typescript -name(): string_t +name(): String_ ``` **Example:** ```typescript -const var1 = new variable_t("`X"); +const var1 = new Variable("`X"); console.log(var1.name().toString()); // "X" console.log(var1.toString()); // "`X" ``` --- -## item_t +## Item Wrapper class for items (constants/functors) in the deductive system. ### Constructor ```typescript -constructor(value: string | Buffer | item_t, size?: number) +constructor(value: string | Buffer | Item, size?: number) ``` ### Methods -Inherits all methods from `string_t`, plus: +Inherits all methods from `String_`, plus: #### name() Get the name of this item. ```typescript -name(): string_t +name(): String_ ``` **Example:** ```typescript -const item = new item_t("atom"); +const item = new Item("atom"); console.log(item.name().toString()); // "atom" ``` --- -## list_t +## List Wrapper class for lists in the deductive system. ### Constructor ```typescript -constructor(value: string | Buffer | list_t, size?: number) +constructor(value: string | Buffer | List, size?: number) ``` ### Methods -Inherits all methods from `string_t`, plus: +Inherits all methods from `String_`, plus: #### length() @@ -200,39 +200,39 @@ length(): number Get an element from the list by index. ```typescript -getitem(index: number): term_t +getitem(index: number): Term ``` **Example:** ```typescript -const list = new list_t("(a b c)"); +const list = new List("(a b c)"); console.log(list.length()); // 3 console.log(list.getitem(0).toString()); // "a" ``` --- -## term_t +## Term Wrapper class for logical terms in the deductive system. A term can be a variable, item, or list. ### Constructor ```typescript -constructor(value: string | Buffer | term_t, size?: number) +constructor(value: string | Buffer | Term, size?: number) ``` ### Methods -Inherits all methods from `string_t`, plus: +Inherits all methods from `String_`, plus: #### term() Extracts the underlying term and returns it as its concrete type. ```typescript -term(): variable_t | item_t | list_t +term(): Variable | Item | List ``` #### ground() @@ -240,7 +240,7 @@ term(): variable_t | item_t | list_t Ground this term using a dictionary to substitute variables with values. ```typescript -ground(other: term_t, scope?: string): term_t | null +ground(other: Term, scope?: string): Term | null ``` **Parameters:** @@ -253,8 +253,8 @@ ground(other: term_t, scope?: string): term_t | null **Example:** ```typescript -const a = new term_t("`a"); -const dict = new term_t("((`a b))"); +const a = new Term("`a"); +const dict = new Term("((`a b))"); const result = a.ground(dict); if (result !== null) { console.log(result.toString()); // "b" @@ -266,7 +266,7 @@ if (result !== null) { Match two terms and return the unification result as a dictionary. ```typescript -match(other: term_t): term_t | null +match(other: Term): Term | null ``` **Parameters:** @@ -278,8 +278,8 @@ match(other: term_t): term_t | null **Example:** ```typescript -const a = new term_t("`a"); -const b = new term_t("b"); +const a = new Term("`a"); +const b = new Term("b"); const result = a.match(b); if (result !== null) { console.log(result.toString()); // "((1 2 `a b))" @@ -291,7 +291,7 @@ if (result !== null) { Rename all variables in this term by adding prefix and suffix. ```typescript -rename(prefix_and_suffix: term_t): term_t | null +rename(prefix_and_suffix: Term): Term | null ``` **Parameters:** @@ -303,8 +303,8 @@ rename(prefix_and_suffix: term_t): term_t | null **Example:** ```typescript -const term = new term_t("`x"); -const spec = new term_t("((pre_) (_suf))"); +const term = new Term("`x"); +const spec = new Term("((pre_) (_suf))"); const result = term.rename(spec); if (result !== null) { console.log(result.toString()); // "`pre_x_suf" @@ -313,19 +313,19 @@ if (result !== null) { --- -## rule_t +## Rule Wrapper class for logical rules in the deductive system. ### Constructor ```typescript -constructor(value: string | Buffer | rule_t, size?: number) +constructor(value: string | Buffer | Rule, size?: number) ``` ### Methods -Inherits all methods from `string_t`, plus: +Inherits all methods from `String_`, plus: #### length() @@ -340,7 +340,7 @@ length(): number Get a premise term by index. ```typescript -getitem(index: number): term_t +getitem(index: number): Term ``` #### conclusion() @@ -348,7 +348,7 @@ getitem(index: number): term_t Get the conclusion of the rule. ```typescript -conclusion(): term_t +conclusion(): Term ``` #### ground() @@ -356,7 +356,7 @@ conclusion(): term_t Ground this rule using a dictionary. ```typescript -ground(other: rule_t, scope?: string): rule_t | null +ground(other: Rule, scope?: string): Rule | null ``` #### match() @@ -364,7 +364,7 @@ ground(other: rule_t, scope?: string): rule_t | null Match this rule with another rule using unification. ```typescript -match(other: rule_t): rule_t | null +match(other: Rule): Rule | null ``` **Parameters:** @@ -376,8 +376,8 @@ match(other: rule_t): rule_t | null **Example:** ```typescript -const mp = new rule_t("(`p -> `q)\n`p\n`q\n"); -const pq = new rule_t("((! (! `x)) -> `x)"); +const mp = new Rule("(`p -> `q)\n`p\n`q\n"); +const pq = new Rule("((! (! `x)) -> `x)"); const result = mp.match(pq); if (result !== null) { console.log(result.toString()); @@ -390,12 +390,12 @@ if (result !== null) { Rename all variables in this rule. ```typescript -rename(prefix_and_suffix: rule_t): rule_t | null +rename(prefix_and_suffix: Rule): Rule | null ``` --- -## search_t +## Search Search engine for the deductive system. @@ -451,7 +451,7 @@ add(text: string): boolean Execute the search engine with a callback for each inferred rule. ```typescript -execute(callback: (candidate: rule_t) => boolean): number +execute(callback: (candidate: Rule) => boolean): number ``` **Parameters:** @@ -463,7 +463,7 @@ execute(callback: (candidate: rule_t) => boolean): number **Example:** ```typescript -const search = new search_t(1000, 10000); +const search = new Search(1000, 10000); search.add("(`P -> `Q) `P `Q"); search.add("(! (! X))"); @@ -482,23 +482,23 @@ Here's a complete example demonstrating most of the TypeScript API: ```typescript import { buffer_size, - string_t, - variable_t, - item_t, - list_t, - term_t, - rule_t, - search_t + String_, + Variable, + Item, + List, + Term, + Rule, + Search } from "atsds"; // Configure buffer size buffer_size(2048); // Create terms -const varX = new variable_t("`X"); -const item = new item_t("hello"); -const lst = new list_t("(a b c)"); -const term = new term_t("(f `x `y)"); +const varX = new Variable("`X"); +const item = new Item("hello"); +const lst = new List("(a b c)"); +const term = new Term("(f `x `y)"); console.log(`Variable: ${varX.toString()}, name: ${varX.name().toString()}`); console.log(`Item: ${item.toString()}, name: ${item.name().toString()}`); @@ -506,30 +506,30 @@ console.log(`List: ${lst.toString()}, length: ${lst.length()}`); console.log(`Term: ${term.toString()}`); // Work with rules -const fact = new rule_t("(parent john mary)"); -const rule = new rule_t("(father `X `Y)\n----------\n(parent `X `Y)\n"); +const fact = new Rule("(parent john mary)"); +const rule = new Rule("(father `X `Y)\n----------\n(parent `X `Y)\n"); console.log(`\nFact: ${fact.toString()}`); console.log(`Rule premises: ${rule.length()}, conclusion: ${rule.conclusion().toString()}`); // Grounding -const termA = new term_t("`a"); -const dictionary = new term_t("((`a hello))"); +const termA = new Term("`a"); +const dictionary = new Term("((`a hello))"); const grounded = termA.ground(dictionary); if (grounded) { console.log(`\nGrounding \`a with ((\`a hello)): ${grounded.toString()}`); } // Matching -const mp = new rule_t("(`p -> `q)\n`p\n`q\n"); -const axiom = new rule_t("((A) -> B)"); +const mp = new Rule("(`p -> `q)\n`p\n`q\n"); +const axiom = new Rule("((A) -> B)"); const matched = mp.match(axiom); if (matched) { console.log(`\nMatching modus ponens with (A -> B):\n${matched.toString()}`); } // Search engine -const search = new search_t(1000, 10000); +const search = new Search(1000, 10000); search.add("p q"); // p implies q search.add("q r"); // q implies r search.add("p"); // fact: p @@ -544,7 +544,7 @@ for (let i = 0; i < 3; i++) { } // Copying and comparison -const rule1 = new rule_t("(a b c)"); +const rule1 = new Rule("(a b c)"); const rule2 = rule1.copy(); console.log(`\nRule comparison: ${rule1.key() === rule2.key()}`); // true ``` diff --git a/docs/concepts/rules.md b/docs/concepts/rules.md index b4f8f38..ddd2319 100644 --- a/docs/concepts/rules.md +++ b/docs/concepts/rules.md @@ -82,13 +82,13 @@ The last term is the conclusion, and all preceding terms are premises. === "TypeScript" ```typescript - import { rule_t } from "atsds"; + import { Rule } from "atsds"; // Create a fact - const fact = new rule_t("(parent john mary)"); + const fact = new Rule("(parent john mary)"); // Create a rule with premises - const rule = new rule_t("(father `X `Y)\n----------\n(parent `X `Y)\n"); + const rule = new Rule("(father `X `Y)\n----------\n(parent `X `Y)\n"); // Access rule components console.log(`Number of premises: ${rule.length()}`); // 1 @@ -145,13 +145,13 @@ Grounding substitutes variables in a rule with values from a dictionary. === "TypeScript" ```typescript - import { rule_t } from "atsds"; + import { Rule } from "atsds"; // Create a rule with variables - const rule = new rule_t("`a"); + const rule = new Rule("`a"); // Create a dictionary - const dictionary = new rule_t("((`a b))"); + const dictionary = new Rule("((`a b))"); // Ground the rule const result = rule.ground(dictionary); @@ -208,13 +208,13 @@ Matching unifies the first premise of a rule with a fact, producing a new rule w === "TypeScript" ```typescript - import { rule_t } from "atsds"; + import { Rule } from "atsds"; // Modus ponens rule - const mp = new rule_t("(`p -> `q)\n`p\n`q\n"); + const mp = new Rule("(`p -> `q)\n`p\n`q\n"); // Double negation elimination axiom - const axiom = new rule_t("((! (! `x)) -> `x)"); + const axiom = new Rule("((! (! `x)) -> `x)"); // Match const result = mp.match(axiom); @@ -278,13 +278,13 @@ Renaming adds prefixes and/or suffixes to all variables in a rule. === "TypeScript" ```typescript - import { rule_t } from "atsds"; + import { Rule } from "atsds"; // Create a rule - const rule = new rule_t("`x"); + const rule = new Rule("`x"); // Rename with prefix and suffix - const spec = new rule_t("((pre_) (_suf))"); + const spec = new Rule("((pre_) (_suf))"); const result = rule.rename(spec); if (result !== null) { console.log(result.toString()); // ----\n`pre_x_suf\n @@ -337,11 +337,11 @@ Rules can be compared for equality. Two rules are equal if they have the same bi === "TypeScript" ```typescript - import { rule_t } from "atsds"; + import { Rule } from "atsds"; - const rule1 = new rule_t("(a b c)"); - const rule2 = new rule_t("(a b c)"); - const rule3 = new rule_t("(a b d)"); + const rule1 = new Rule("(a b c)"); + const rule2 = new Rule("(a b c)"); + const rule3 = new Rule("(a b d)"); console.log(rule1.key() === rule2.key()); // true console.log(rule1.key() === rule3.key()); // false diff --git a/docs/concepts/search.md b/docs/concepts/search.md index 13e216e..237572f 100644 --- a/docs/concepts/search.md +++ b/docs/concepts/search.md @@ -37,13 +37,13 @@ The search engine: === "TypeScript" ```typescript - import { search_t } from "atsds"; + import { Search } from "atsds"; // Create with default sizes - const search = new search_t(); + const search = new Search(); // Create with custom sizes - const search2 = new search_t(1000, 10000); + const search2 = new Search(1000, 10000); ``` === "C++" @@ -81,9 +81,9 @@ Use the `add()` method to add rules and facts to the knowledge base. === "TypeScript" ```typescript - import { search_t } from "atsds"; + import { Search } from "atsds"; - const search = new search_t(); + const search = new Search(); // Add a fact search.add("(parent john mary)"); @@ -129,9 +129,9 @@ The `execute()` method performs one round of inference. It matches all rules aga === "TypeScript" ```typescript - import { search_t } from "atsds"; + import { Search } from "atsds"; - const search = new search_t(); + const search = new Search(); search.add("(father `X `Y)\n----------\n(parent `X `Y)\n"); search.add("(father john mary)"); @@ -202,9 +202,9 @@ To search until a specific target is found: === "TypeScript" ```typescript - import { rule_t, search_t } from "atsds"; + import { Rule, Search } from "atsds"; - const search = new search_t(1000, 10000); + const search = new Search(1000, 10000); // Set up propositional logic search.add("(`P -> `Q) `P `Q"); @@ -213,7 +213,7 @@ To search until a specific target is found: search.add("(((! `p) -> (! `q)) -> (`q -> `p))"); search.add("(! (! X))"); - const target = new rule_t("X"); + const target = new Rule("X"); while (true) { let found = false; diff --git a/docs/concepts/terms.md b/docs/concepts/terms.md index 76189f6..ac6b150 100644 --- a/docs/concepts/terms.md +++ b/docs/concepts/terms.md @@ -73,25 +73,25 @@ Lists are the primary way to build complex structures in the deductive system. T === "TypeScript" ```typescript - import { variable_t, item_t, list_t, term_t } from "atsds"; + import { Variable, Item, List, Term } from "atsds"; // Create a variable - const var1 = new variable_t("`X"); + const var1 = new Variable("`X"); console.log(`Variable name: ${var1.name().toString()}`); // X // Create an item - const item = new item_t("hello"); + const item = new Item("hello"); console.log(`Item name: ${item.name().toString()}`); // hello // Create a list - const lst = new list_t("(a b c)"); + const lst = new List("(a b c)"); console.log(`List length: ${lst.length()}`); // 3 console.log(`First element: ${lst.getitem(0).toString()}`); // a // Create a generic term - const term = new term_t("(f `x)"); + const term = new Term("(f `x)"); // Access the underlying type - const inner = term.term(); // Returns a list_t + const inner = term.term(); // Returns a List ``` === "Python" @@ -145,13 +145,13 @@ Grounding substitutes variables in a term with values from a dictionary. The dic === "TypeScript" ```typescript - import { term_t } from "atsds"; + import { Term } from "atsds"; // Create a term with a variable - const term = new term_t("`a"); + const term = new Term("`a"); // Create a dictionary for substitution - const dictionary = new term_t("((`a b))"); + const dictionary = new Term("((`a b))"); // Ground the term const result = term.ground(dictionary); @@ -209,11 +209,11 @@ Matching unifies two terms and returns a dictionary of variable bindings. The di === "TypeScript" ```typescript - import { term_t } from "atsds"; + import { Term } from "atsds"; // Match a variable with a value - const a = new term_t("`a"); - const b = new term_t("value"); + const a = new Term("`a"); + const b = new Term("value"); const result = a.match(b); if (result !== null) { @@ -221,8 +221,8 @@ Matching unifies two terms and returns a dictionary of variable bindings. The di } // Match complex terms - const term1 = new term_t("(f b a)"); - const term2 = new term_t("(f `x a)"); + const term1 = new Term("(f b a)"); + const term2 = new Term("(f `x a)"); const dict = term1.match(term2); if (dict !== null) { @@ -280,13 +280,13 @@ Renaming adds prefixes and/or suffixes to all variables in a term. This is usefu === "TypeScript" ```typescript - import { term_t } from "atsds"; + import { Term } from "atsds"; // Create a term with a variable - const term = new term_t("`x"); + const term = new Term("`x"); // Create prefix and suffix specification - const spec = new term_t("((pre_) (_suf))"); + const spec = new Term("((pre_) (_suf))"); // Rename the term const result = term.rename(spec); diff --git a/docs/examples/Sudoku.vue b/docs/examples/Sudoku.vue index b24481f..582c651 100644 --- a/docs/examples/Sudoku.vue +++ b/docs/examples/Sudoku.vue @@ -236,7 +236,7 @@ textarea:focus { ``` @@ -174,9 +174,9 @@ ctest === "TypeScript" ```typescript - import { term_t } from "atsds"; + import { Term } from "atsds"; - const term = new term_t("(hello world)"); + const term = new Term("(hello world)"); console.log(term.toString()); // Output: (hello world) ``` diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 9d93b64..1641d6f 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -30,13 +30,13 @@ Terms are the basic building blocks of the deductive system. A term can be: === "TypeScript" ```typescript - import { variable_t, item_t, list_t, term_t } from "atsds"; + import { Variable, Item, List, Term } from "atsds"; // Create different types of terms - const var1 = new variable_t("`X"); - const item = new item_t("hello"); - const lst = new list_t("(a b c)"); - const term = new term_t("(f `x a)"); + const var1 = new Variable("`X"); + const item = new Item("hello"); + const lst = new List("(a b c)"); + const term = new Term("(f `x a)"); console.log(`Variable: ${var1.toString()}`); // `X console.log(`Item: ${item.toString()}`); // hello @@ -81,14 +81,14 @@ Rules represent logical inference steps. A rule has premises (conditions) and a === "TypeScript" ```typescript - import { rule_t } from "atsds"; + import { Rule } from "atsds"; // A fact (rule with no premises) - const fact = new rule_t("(parent john mary)"); + const fact = new Rule("(parent john mary)"); console.log(`Fact: ${fact.toString()}`); // A rule with premises - const rule = new rule_t("(father `X `Y)\n----------\n(parent `X `Y)\n"); + const rule = new Rule("(father `X `Y)\n----------\n(parent `X `Y)\n"); console.log(`Rule premises: ${rule.length()}`); console.log(`Rule conclusion: ${rule.conclusion().toString()}`); ``` @@ -154,10 +154,10 @@ The search engine performs logical inference by matching rules with facts. === "TypeScript" ```typescript - import { rule_t, search_t } from "atsds"; + import { Rule, Search } from "atsds"; // Create search engine - const search = new search_t(1000, 10000); + const search = new Search(1000, 10000); // Add modus ponens: P -> Q, P |- Q search.add("(`P -> `Q) `P `Q"); @@ -171,7 +171,7 @@ The search engine performs logical inference by matching rules with facts. search.add("(! (! X))"); // Define target: X - const target = new rule_t("X"); + const target = new Rule("X"); // Execute search while (true) { diff --git a/docs/index.md b/docs/index.md index 9445cfd..1532ceb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,9 +17,9 @@ A deductive system for logical inference, implemented in C++. The library provid === "TypeScript" ```typescript - import { term_t } from "atsds"; + import { Term } from "atsds"; - const term = new term_t("(hello world)"); + const term = new Term("(hello world)"); console.log(term.toString()); // Output: (hello world) ``` diff --git a/examples/main.mjs b/examples/main.mjs index 09b6a79..9255898 100644 --- a/examples/main.mjs +++ b/examples/main.mjs @@ -1,4 +1,4 @@ -import { rule_t, search_t, buffer_size } from "../atsds/index.mts"; +import { Rule, Search, buffer_size } from "../atsds/index.mts"; function main() { const temp_data_size = 1000; @@ -6,7 +6,7 @@ function main() { const single_result_size = 10000; buffer_size(temp_text_size); - const search = new search_t(temp_data_size, single_result_size); + const search = new Search(temp_data_size, single_result_size); // P -> Q, P |- Q search.add("(`P -> `Q) `P `Q"); @@ -20,7 +20,7 @@ function main() { // premise search.add("(! (! X))"); - const target = new rule_t("X"); + const target = new Rule("X"); while (true) { let success = false; diff --git a/tests/test_item.mjs b/tests/test_item.mjs index 69923a2..11b143f 100644 --- a/tests/test_item.mjs +++ b/tests/test_item.mjs @@ -1,9 +1,9 @@ -import { item_t, buffer_size } from "../atsds/index.mts"; +import { Item, buffer_size } from "../atsds/index.mts"; let v = null; beforeEach(() => { - v = new item_t("item"); + v = new Item("item"); }); test("toString", () => { @@ -23,31 +23,31 @@ test("key", () => { }); test("create_from_same", () => { - const v2 = new item_t(v); + const v2 = new Item(v); expect(v2.toString()).toBe("item"); - expect(() => new item_t(v, 100)).toThrow(); + expect(() => new Item(v, 100)).toThrow(); }); test("create_from_base", () => { - const v2 = new item_t(v.value); + const v2 = new Item(v.value); expect(v2.toString()).toBe("item"); }); test("create_from_text", () => { - const v2 = new item_t("item"); + const v2 = new Item("item"); expect(v2.toString()).toBe("item"); }); test("create_from_bytes", () => { - const v2 = new item_t(v.data()); + const v2 = new Item(v.data()); expect(v2.toString()).toBe("item"); - expect(() => new item_t(v.data(), 100)).toThrow(); + expect(() => new Item(v.data(), 100)).toThrow(); }); test("create_fail", () => { - expect(() => new item_t(100)).toThrow(); + expect(() => new Item(100)).toThrow(); }); test("name", () => { diff --git a/tests/test_list.mjs b/tests/test_list.mjs index 14737d3..b7982b0 100644 --- a/tests/test_list.mjs +++ b/tests/test_list.mjs @@ -1,9 +1,9 @@ -import { list_t, buffer_size } from "../atsds/index.mts"; +import { List, buffer_size } from "../atsds/index.mts"; let v = null; beforeEach(() => { - v = new list_t("(a b c)"); + v = new List("(a b c)"); }); test("toString", () => { @@ -23,31 +23,31 @@ test("key", () => { }); test("create_from_same", () => { - const v2 = new list_t(v); + const v2 = new List(v); expect(v2.toString()).toBe("(a b c)"); - expect(() => new list_t(v, 100)).toThrow(); + expect(() => new List(v, 100)).toThrow(); }); test("create_from_base", () => { - const v2 = new list_t(v.value); + const v2 = new List(v.value); expect(v2.toString()).toBe("(a b c)"); }); test("create_from_text", () => { - const v2 = new list_t("(a b c)"); + const v2 = new List("(a b c)"); expect(v2.toString()).toBe("(a b c)"); }); test("create_from_bytes", () => { - const v2 = new list_t(v.data()); + const v2 = new List(v.data()); expect(v2.toString()).toBe("(a b c)"); - expect(() => new list_t(v.data(), 100)).toThrow(); + expect(() => new List(v.data(), 100)).toThrow(); }); test("create_fail", () => { - expect(() => new list_t(100)).toThrow(); + expect(() => new List(100)).toThrow(); }); test("length", () => { diff --git a/tests/test_rule.mjs b/tests/test_rule.mjs index faea126..12af731 100644 --- a/tests/test_rule.mjs +++ b/tests/test_rule.mjs @@ -1,9 +1,9 @@ -import { rule_t, buffer_size } from "../atsds/index.mts"; +import { Rule, buffer_size } from "../atsds/index.mts"; let v = null; beforeEach(() => { - v = new rule_t("(a b c)"); + v = new Rule("(a b c)"); }); test("toString", () => { @@ -23,40 +23,40 @@ test("key", () => { }); test("create_from_same", () => { - const v2 = new rule_t(v); + const v2 = new Rule(v); expect(v2.toString()).toBe("----\n(a b c)\n"); - expect(() => new rule_t(v, 100)).toThrow(); + expect(() => new Rule(v, 100)).toThrow(); }); test("create_from_base", () => { - const v2 = new rule_t(v.value); + const v2 = new Rule(v.value); expect(v2.toString()).toBe("----\n(a b c)\n"); }); test("create_from_text", () => { - const v2 = new rule_t("(a b c)"); + const v2 = new Rule("(a b c)"); expect(v2.toString()).toBe("----\n(a b c)\n"); }); test("create_from_bytes", () => { - const v2 = new rule_t(v.data()); + const v2 = new Rule(v.data()); expect(v2.toString()).toBe("----\n(a b c)\n"); - expect(() => new rule_t(v.data(), 100)).toThrow(); + expect(() => new Rule(v.data(), 100)).toThrow(); }); test("create_fail", () => { - expect(() => new rule_t(100)).toThrow(); + expect(() => new Rule(100)).toThrow(); }); test("length", () => { - const v2 = new rule_t("(p -> q)\np\nq\n"); + const v2 = new Rule("(p -> q)\np\nq\n"); expect(v2.length()).toBe(2); }); test("getitem", () => { - const v2 = new rule_t("(p -> q)\np\nq\n"); + const v2 = new Rule("(p -> q)\np\nq\n"); expect(v2.getitem(0).toString()).toBe("(p -> q)"); expect(v2.getitem(1).toString()).toBe("p"); @@ -65,59 +65,59 @@ test("getitem", () => { }); test("conclusion", () => { - const v2 = new rule_t("(p -> q)\np\nq\n"); + const v2 = new Rule("(p -> q)\np\nq\n"); expect(v2.conclusion().toString()).toBe("q"); }); test("ground_simple", () => { - const a = new rule_t("`a"); - const b = new rule_t("((`a b))"); + const a = new Rule("`a"); + const b = new Rule("((`a b))"); expect(a.ground(b).toString()).toBe("----\nb\n"); - expect(a.ground(new rule_t("((`a b c d e))"))).toBeNull(); + expect(a.ground(new Rule("((`a b c d e))"))).toBeNull(); }); test("ground_scope", () => { - const a = new rule_t("`a"); - const b = new rule_t("((x y `a `b) (y x `b `c))"); + const a = new Rule("`a"); + const b = new Rule("((x y `a `b) (y x `b `c))"); expect(a.ground(b, "x").toString()).toBe("----\n`c\n"); }); test("match", () => { - const mp = new rule_t("(`p -> `q)\n`p\n`q\n"); - const pq = new rule_t("((! (! `x)) -> `x)"); + const mp = new Rule("(`p -> `q)\n`p\n`q\n"); + const pq = new Rule("((! (! `x)) -> `x)"); expect(mp.match(pq).toString()).toBe("(! (! `x))\n----------\n`x\n"); - fail = new rule_t("(`q <- `p)"); + const fail = new Rule("(`q <- `p)"); expect(mp.match(fail)).toBeNull(); }); test("rename_simple", () => { - const a = new rule_t("`x"); - const b = new rule_t("((pre_) (_suf))"); + const a = new Rule("`x"); + const b = new Rule("((pre_) (_suf))"); expect(a.rename(b).toString()).toBe("----\n`pre_x_suf\n"); }); test("rename_empty_prefix", () => { - const a = new rule_t("`x"); - const b = new rule_t("(() (_suf))"); + const a = new Rule("`x"); + const b = new Rule("(() (_suf))"); expect(a.rename(b).toString()).toBe("----\n`x_suf\n"); }); test("rename_empty_suffix", () => { - const a = new rule_t("`x"); - const b = new rule_t("((pre_) ())"); + const a = new Rule("`x"); + const b = new Rule("((pre_) ())"); expect(a.rename(b).toString()).toBe("----\n`pre_x\n"); }); test("rename_with_premises", () => { - const a = new rule_t("`p\n`q\n----------\n`r\n"); - const b = new rule_t("((pre_) (_suf))"); + const a = new Rule("`p\n`q\n----------\n`r\n"); + const b = new Rule("((pre_) (_suf))"); expect(a.rename(b).toString()).toBe("`pre_p_suf\n`pre_q_suf\n----------\n`pre_r_suf\n"); }); test("rename_invalid", () => { - const a = new rule_t("`x"); - const b = new rule_t("item"); + const a = new Rule("`x"); + const b = new Rule("item"); expect(a.rename(b)).toBeNull(); }); diff --git a/tests/test_search.mjs b/tests/test_search.mjs index 2ac7a4c..eb03c57 100644 --- a/tests/test_search.mjs +++ b/tests/test_search.mjs @@ -1,9 +1,9 @@ -import { search_t, rule_t } from "../atsds/index.mts"; +import { Search, Rule } from "../atsds/index.mts"; let search = null; beforeEach(() => { - search = new search_t(100, 1000); + search = new Search(100, 1000); }); test("reset_parameters", () => { @@ -25,7 +25,7 @@ test("add_fail", () => { test("execute_single", () => { search.add("p q"); search.add("p"); - const target = new rule_t("q"); + const target = new Rule("q"); let success = false; const count = search.execute((rule) => { if (rule.key() === target.key()) { @@ -41,8 +41,8 @@ test("execute_long", () => { search.add("p q r"); search.add("p"); search.add("q"); - const target1 = new rule_t("q r"); - const target2 = new rule_t("r"); + const target1 = new Rule("q r"); + const target2 = new Rule("r"); let success1 = false; let success2 = false; count1 = search.execute((rule) => { diff --git a/tests/test_string.mjs b/tests/test_string.mjs index fe08677..0fdd0ee 100644 --- a/tests/test_string.mjs +++ b/tests/test_string.mjs @@ -1,9 +1,9 @@ -import { string_t, buffer_size } from "../atsds/index.mts"; +import { String_, buffer_size } from "../atsds/index.mts"; let v = null; beforeEach(() => { - v = new string_t("string"); + v = new String_("string"); }); test("toString", () => { @@ -23,29 +23,29 @@ test("key", () => { }); test("create_from_same", () => { - const v2 = new string_t(v); + const v2 = new String_(v); expect(v2.toString()).toBe("string"); - expect(() => new string_t(v, 100)).toThrow(); + expect(() => new String_(v, 100)).toThrow(); }); test("create_from_base", () => { - const v2 = new string_t(v.value); + const v2 = new String_(v.value); expect(v2.toString()).toBe("string"); }); test("create_from_text", () => { - const v2 = new string_t("string"); + const v2 = new String_("string"); expect(v2.toString()).toBe("string"); }); test("create_from_bytes", () => { - const v2 = new string_t(v.data()); + const v2 = new String_(v.data()); expect(v2.toString()).toBe("string"); - expect(() => new string_t(v.data(), 100)).toThrow(); + expect(() => new String_(v.data(), 100)).toThrow(); }); test("create_fail", () => { - expect(() => new string_t(100)).toThrow(); + expect(() => new String_(100)).toThrow(); }); diff --git a/tests/test_term.mjs b/tests/test_term.mjs index dc9face..876ac1e 100644 --- a/tests/test_term.mjs +++ b/tests/test_term.mjs @@ -1,9 +1,9 @@ -import { list_t, item_t, variable_t, term_t, buffer_size } from "../atsds/index.mts"; +import { List, Item, Variable, Term, buffer_size } from "../atsds/index.mts"; let v = null; beforeEach(() => { - v = new term_t("(a b c)"); + v = new Term("(a b c)"); }); test("toString", () => { @@ -23,102 +23,102 @@ test("key", () => { }); test("create_from_same", () => { - const v2 = new term_t(v); + const v2 = new Term(v); expect(v2.toString()).toBe("(a b c)"); - expect(() => new term_t(v, 100)).toThrow(); + expect(() => new Term(v, 100)).toThrow(); }); test("create_from_base", () => { - const v2 = new term_t(v.value); + const v2 = new Term(v.value); expect(v2.toString()).toBe("(a b c)"); }); test("create_from_text", () => { - const v2 = new term_t("(a b c)"); + const v2 = new Term("(a b c)"); expect(v2.toString()).toBe("(a b c)"); }); test("create_from_bytes", () => { - const v2 = new term_t(v.data()); + const v2 = new Term(v.data()); expect(v2.toString()).toBe("(a b c)"); - expect(() => new term_t(v.data(), 100)).toThrow(); + expect(() => new Term(v.data(), 100)).toThrow(); }); test("create_fail", () => { - expect(() => new term_t(100)).toThrow(); + expect(() => new Term(100)).toThrow(); }); test("term", () => { - expect(new term_t("()").term()).toBeInstanceOf(list_t); - expect(new term_t("a").term()).toBeInstanceOf(item_t); - expect(new term_t("`a").term()).toBeInstanceOf(variable_t); + expect(new Term("()").term()).toBeInstanceOf(List); + expect(new Term("a").term()).toBeInstanceOf(Item); + expect(new Term("`a").term()).toBeInstanceOf(Variable); }); test("ground_simple", () => { - const a = new term_t("`a"); - const b = new term_t("((`a b))"); + const a = new Term("`a"); + const b = new Term("((`a b))"); expect(a.ground(b).toString()).toBe("b"); - expect(a.ground(new term_t("((`a b c d e))"))).toBeNull(); + expect(a.ground(new Term("((`a b c d e))"))).toBeNull(); }); test("ground_scope", () => { - const a = new term_t("`a"); - const b = new term_t("((x y `a `b) (y x `b `c))"); + const a = new Term("`a"); + const b = new Term("((x y `a `b) (y x `b `c))"); expect(a.ground(b, "x").toString()).toBe("`c"); }); test("rename_simple", () => { - const a = new term_t("`x"); - const b = new term_t("((pre_) (_suf))"); + const a = new Term("`x"); + const b = new Term("((pre_) (_suf))"); expect(a.rename(b).toString()).toBe("`pre_x_suf"); }); test("rename_empty_prefix", () => { - const a = new term_t("`x"); - const b = new term_t("(() (_suf))"); + const a = new Term("`x"); + const b = new Term("(() (_suf))"); expect(a.rename(b).toString()).toBe("`x_suf"); }); test("rename_empty_suffix", () => { - const a = new term_t("`x"); - const b = new term_t("((pre_) ())"); + const a = new Term("`x"); + const b = new Term("((pre_) ())"); expect(a.rename(b).toString()).toBe("`pre_x"); }); test("rename_list", () => { - const a = new term_t("(`x `y)"); - const b = new term_t("((p_) (_s))"); + const a = new Term("(`x `y)"); + const b = new Term("((p_) (_s))"); expect(a.rename(b).toString()).toBe("(`p_x_s `p_y_s)"); }); test("rename_invalid", () => { - const a = new term_t("`x"); - const b = new term_t("item"); + const a = new Term("`x"); + const b = new Term("item"); expect(a.rename(b)).toBeNull(); }); test("match_simple", () => { - const a = new term_t("`a"); - const b = new term_t("b"); + const a = new Term("`a"); + const b = new Term("b"); const result = a.match(b); expect(result).not.toBeNull(); expect(result.toString()).toBe("((1 2 `a b))"); }); test("match_complex", () => { - const a = new term_t("(f b a)"); - const b = new term_t("(f `x a)"); + const a = new Term("(f b a)"); + const b = new Term("(f `x a)"); const result = a.match(b); expect(result).not.toBeNull(); expect(result.toString()).toBe("((2 1 `x b))"); }); test("match_fail", () => { - const a = new term_t("(f `x)"); - const b = new term_t("(g `y)"); + const a = new Term("(f `x)"); + const b = new Term("(g `y)"); const result = a.match(b); expect(result).toBeNull(); }); diff --git a/tests/test_variable.mjs b/tests/test_variable.mjs index d829d86..4e35209 100644 --- a/tests/test_variable.mjs +++ b/tests/test_variable.mjs @@ -1,9 +1,9 @@ -import { variable_t, buffer_size } from "../atsds/index.mts"; +import { Variable, buffer_size } from "../atsds/index.mts"; let v = null; beforeEach(() => { - v = new variable_t("`variable"); + v = new Variable("`variable"); }); test("toString", () => { @@ -23,31 +23,31 @@ test("key", () => { }); test("create_from_same", () => { - const v2 = new variable_t(v); + const v2 = new Variable(v); expect(v2.toString()).toBe("`variable"); - expect(() => new variable_t(v, 100)).toThrow(); + expect(() => new Variable(v, 100)).toThrow(); }); test("create_from_base", () => { - const v2 = new variable_t(v.value); + const v2 = new Variable(v.value); expect(v2.toString()).toBe("`variable"); }); test("create_from_text", () => { - const v2 = new variable_t("`variable"); + const v2 = new Variable("`variable"); expect(v2.toString()).toBe("`variable"); }); test("create_from_bytes", () => { - const v2 = new variable_t(v.data()); + const v2 = new Variable(v.data()); expect(v2.toString()).toBe("`variable"); - expect(() => new variable_t(v.data(), 100)).toThrow(); + expect(() => new Variable(v.data(), 100)).toThrow(); }); test("create_fail", () => { - expect(() => new variable_t(100)).toThrow(); + expect(() => new Variable(100)).toThrow(); }); test("name", () => {