mthom / scryer-prolog

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

Using as library #2387

Open flashpixx opened 2 months ago

flashpixx commented 2 months ago

Hello,

I'm interested in this project and I'm a Rust newby. I'm working on a project with network e.g. nmap results and I would like to build a microservice with Tokio / Axum to execute Prolog terms. Is it possible to use this project as a library dependency in my project. For my use case I need to read / parse a pl-file with static rules and append facts (terms) which I can build based on my NMAP results and I need to share this instance over multiple threads in Axum, so I get run some post and get HTTP queries (by converting JSON input into prolog terms).

I didn't find this in the documentation. Thanks a lot of helping

aarroyoc commented 2 months ago

There are several ways to do what you want to do. If the only thing you want to do in your microservice is executing Prolog terms, take a look at library(http/http_server), which is a HTTP(S) server which can be used from Prolog. It still has some rough edges, but it may work for you already. I have more samples of this library usage if you want to take this route.

The other way is using Scryer Prolog as a library. This is not documented yet but the methods available to you are under src/machine/lib_machine.rs. Some people are already using them, like https://github.com/coasys

flashpixx commented 2 months ago

I will choose the 2nd option, because I would like to get a single executable later

flashpixx commented 2 months ago

Is there any documentation how to build terms and queries and execute then within code? For my use-case I would like to do:

  1. read a static pl-file with some rules
  2. add multiple facts (terms) based on NMAP results, so I can build strings and pass it into the machine
  3. execute some queries within Tokio HTTP handlers