Repository navigation
Make ?- list tuples and handle typos and arity - #20
Merged
Merged
Conversation
A single plain atom with no named variables (`?- rel`, `?- rel()`,
`?- rel("c", _)`) now lists whole matching tuples instead of
creating a `_N` rule. `_` and missing trailing arguments match
anything. Queries with named variables, or with several atoms, keep
the existing binding path (`X = v`), including `_` padding for
partial atoms.
Typos used to be silent: an unknown relation was an empty result on
the interpreter and an opaque error on DD. Before running any `?-`
query the REPL now rejects relations the engine does not know
(declared, defined by a rule or fact, EDB rows, or in the current
store) and suggests up to three near names. Giving more arguments
than a relation has columns is also an error. This adds
CompiledProgram::defined_relations and Engine::known_relations.
Output formats gain `compact` (bare `rel(a, b)` tuples) and `table`
(aligned columns under a header, cells clipped at 64 characters,
newlines escaped). The default listing now names each column
(`Principal = "...", Namespace = ...`), falling back to c0, c1 when
there is no Decl. `table` also applies to binding results, using
the variable names as headers.
Behavior changes:
* The bare `pred(args)` and `pred` query forms are removed. Input
that is not a command prints "Not a command. Queries start with
?-, e.g. ?- <line>" and an unknown `::cmd` prints "Unknown
command: ...". Use `?- pred(args)` instead.
* The `plain` output format is renamed `default`, with no alias.
`\format plain` and `--format plain` are now rejected. The
default for `--format` is now spelled `default`.
* `\format` accepts `compact` and `table`.
* A `?-` query naming an unknown relation, or passing too many
arguments to one, now errors instead of returning nothing.
* A `?-` conjunction with no named variables now prints "No
variables to bind. Name one (e.g. X)." It previously built a
zero-column rule and printed "No results." or a blank row.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reworks the REPL's query UX around
?-.?- rel,?- rel()and?- rel("c", _, ...)(a single atom with no named variables) now list whole matching tuples. No_Nrule is created._and missing trailing arguments match anything.X = v), including_padding for partial atoms.Unknown relation 'x'. Did you mean: a, b?(up to 3 suggestions by edit distance, skipping_Nresults andx__relsnapshot copies). More arguments than a relation has columns printsrel has N columns, got M arguments.compact(barerel(a, b)tuples) andtable(aligned columns under a header row; cells clipped at 64 characters, newlines escaped).tablealso applies to binding results, with the variable names as headers.Principal = "...", Namespace = ...), falling back toc0, c1when a relation has noDecl.Engine additions:
CompiledProgram::defined_relationsandEngine::known_relations.Behavior changes
pred(args)/predquery form is removed. Non-command input printsNot a command. Queries start with ?-, e.g. ?- <line>, and an unknown::cmdprintsUnknown command: .... Use?- pred(args).plainoutput format is renameddefault, with no alias.\format plainand--format plainare now rejected. The--formatdefault is spelleddefault. (tests/smt_ndjson.rsis updated for the rename.)\formatand--formatacceptcompactandtablein addition todefault,prettyandndjson.?-query naming an unknown relation, or passing too many arguments, is now an error instead of an empty result (interpreter) or an opaque error (DD).?-conjunction with no named variables printsNo variables to bind. Name one (e.g. X).(previously a zero-column rule:No results.or a blank row).::smtbehavior and--format ndjsonoutput are unchanged.Testing
cargo fmt --check,cargo clippy --all-targets --locked -- -D warnings,cargo test --all-targets --lockedall pass on stable.body_relations,suggest,split_top_level_args,single_atom,render_table.tests/repl_query.rsdrives the binary overtestdata/: default listing names columns,\format compact,\format table(header and rule row), unknown relation did-you-mean, too many arguments,plainrejected, baredirect_perm(X)prints the hint.--backend ddagainsttestdata/: listing, partial atom,_wildcard, binding query with:string:contains, typo'd relation, too many arguments, conjunction with no variables, every\formatvalue. Output is identical on both backends.Before / after
Listing (before,
?- direct_perm("developer@example.com")created a zero-column rule and printed a blank row):Typo and arity:
Formats:
Removed bare form:
Binding queries are unchanged:
🤖 Generated with Claude Code