mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.04k stars 119 forks source link

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

Closed triska closed 6 hours ago

triska commented 6 hours ago

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 commented 6 hours ago

What version is this? This is a problem that was solved with https://github.com/mthom/scryer-prolog/pull/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 commented 6 hours ago

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