Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library interface: Unexpected result when calling run_query directly on a Machine struct #2637

Closed
triska opened this issue Oct 21, 2024 · 4 comments

Comments

@triska
Copy link
Contributor

triska commented Oct 21, 2024

Today the following question was raised on the #scryer IRC channel, I file it here as an issue so that we remember it:

Given the fact colleague(joe, mike)., when we query it with colleague(joe, X)., then we get as QueryResolution: Matches([QueryMatch { bindings: {"X": String("mike")} }]).

Question: Why is X is bound to String("mike"), instead of an atom?

Can anyone confirm and explain this, and is more information needed here (@shawa)? Thank you a lot!

@bakaq
Copy link
Contributor

bakaq commented Oct 21, 2024

What version is this? This is a problem that was solved with #2475. On current master this works as intended:

use scryer_prolog::Machine;

pub fn main() -> () {
    let mut machine = Machine::new_lib();

    machine.load_module_string("facts", "colleague(joe, mike).".into());
    let result = machine.run_query("colleague(joe, X).".into()).unwrap();

    println!("{result:?}");
    // Matches([QueryMatch { bindings: {"X": Atom("mike")} }])
}

@triska
Copy link
Contributor Author

triska commented Oct 21, 2024

Excellent, thank you a lot! I am closing this as resolved!

@triska triska closed this as completed Oct 21, 2024
@shawa
Copy link

shawa commented Oct 21, 2024

Looks like this solves the issue; working correctly my end - thanks for taking a look at it!

I'm very new to the project, and Rust, but it looks like this was an issue specifically with the parser - I mentioned on IRC that I'm interested in interop with other languages, and I'm looking at using Elixir as a frontend. It's early days, but I would be even more interested in constructing/manipulating AST directly (bypassing any need to ever actually build/parse Prolog programs/queries as strings altogether), and having a Machine load that.

Is this an avenue the internals are currently amenable to - and if not, where would be a good place to start looking, if I wanted to contribute this capability?

Thanks again for the help!

@triska
Copy link
Contributor Author

triska commented Oct 22, 2024

@shawa: There is currently ongoing work to make Scryer Prolog useable from other languages, please have a look: #2465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants