Skip to content

Commit

Permalink
Merge branch 'main' into docupdate-for-v0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
robsimmons authored Nov 28, 2024
2 parents 61194e7 + a09052d commit 9fa8391
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dusa",
"version": "0.1.3",
"version": "0.1.4",
"type": "module",
"main": "lib/client.js",
"unpkg": "./dusa.umd.js",
Expand Down
14 changes: 14 additions & 0 deletions src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ test('Builtin STRING_CONCAT', () => {
).toStrictEqual(['']);
});

test('Facts', () => {
expect(new Dusa('a. b 1. c 2 3. d e is "f". g (h i) is ().').solution?.facts()).toStrictEqual([
{ name: 'a', args: [] },
{ name: 'b', args: [1] },
{ name: 'c', args: [2, 3] },
{ name: 'd', args: [{ name: 'e' }], value: 'f' },
{ name: 'g', args: [{ name: 'h', args: [{ name: 'i' }] }], value: null },
]);

expect(new Dusa('a 1 () "3" four 5 is ().').solution?.factsBig()).toStrictEqual([
{ name: 'a', args: [1n, null, '3', { name: 'four' }, 5n], value: null },
]);
});

test('Builtin STRING_CONCAT, full reverse', () => {
expect(
solutions(new Dusa('#builtin STRING_CONCAT concat\nres X Y :- concat X Y is "abc".')),
Expand Down
14 changes: 8 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,14 @@ class DusaSolutionImpl implements DusaSolution {
const arity = this.prog.arities[name];
if (!arity) return;
const depth = (arity.value ? arity.args + 1 : arity.args) - args.length;
yield* this.solution.visit(
name,
args.map((arg) => termToData(this.prog.data, arg)),
args.length,
depth,
);
yield* this.solution
.visit(
name,
args.map((arg) => termToData(this.prog.data, arg)),
args.length,
depth,
)
.map((tms) => tms.slice(0));
}

*lookup(name: string, ...args: InputTerm[]) {
Expand Down

0 comments on commit 9fa8391

Please sign in to comment.