13.2 Calling Prolog from JavaScript
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • Using SWI-Prolog in your browser (WASM)
        • Calling Prolog from JavaScript
          • The JavaScript class Query
          • Using engines
          • Translating data between JavaScript and Prolog
    • Packages

13.2.1 The JavaScript class Query

The method Prolog.query() returns an instance of the JavaScript class Query that may be used to explore the solutions of the query. The Query class implements the JavaScript iterator protocol.

Object Query.next()
Implements the iterator protocol. This returns an object holding the keys done and value. If exception handling is enabled it returns an object {done:true, error:true, message:String}.
Object Query.once()
Close the query after the first answer. Returns the .value of the object returned by .next() on success and the complete object on failure or error. In addition, on a logical result (no error), a field success is added with a boolean value. Thus, the return value may contain these keys:
{Bindings}
Query succeeded. Objects holds a key for each output variable. In addition the success key is set to true.
{success:false}
Query failed. Note that the binding keys all start with an uppercase letter and this is thus not ambiguous.
{error:true, message:String}
Query raised an exception.
Object Query.close()
Closes the query. This can be used inside the iterator to stop further enumeration.