mthom / scryer-prolog

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

scryper-prolog as a library #225

Closed uraj closed 10 months ago

uraj commented 4 years ago

I was wondering if it's possible to use scryper-prolog as a library such that it can be embedded into other applications as a backend for solving certain logic puzzles.

triska commented 4 years ago

Is there a reason to use a library for this? One very good solution for such use cases is often to use well-established interface mechanisms such as pipes, files or sockets to communicate between the two processes. This allows easier coupling and debugging, and also keeps the core small.

One important feature to easily communicate between processes is described in #187 (update: and it is now already available). With this command line option, you can dynamically specify a goal, and get the output via standard mechanisms directly from the Scryer process.

uraj commented 4 years ago

I'm considering using Prolog inside SGX, a hardware feature available for some Intel CPUs. In SGX mode, performing I/O is expensive and can be extremely insecure. That's why a library is more desired.

mthom commented 4 years ago

You could always package the machine submodule as a library, sure. I'm not thrilled with the way expansions and the toplevel interaction are currently handled, though. I would want to revise them to be faster and more Prolog- rather than Rust-based, as they now are. Their current form is a holdover from the early days of the project.

Immortalin commented 4 years ago

I am considering using scryer as a parser frontend for a JIT interpreter (the parser is written in prolog). Would be great if it's embeddable.

hashedone commented 4 years ago

I also think this is a great idea - I would like to use some prolog-like machine for type resolution for experimental language (and this is exactly what Rust is doing with chalk, so it's tested idea). Communication via pipes/sockets kills performance.

shonfeder commented 3 years ago

I came in search of this this too.

ghost commented 3 years ago

A start solution would be to write a src/lib.rs with all the modules, then the visibility/privacy problem can be solved later with an example/reason to use a data structure, function, ...

shonfeder commented 3 years ago

Yeah, that'd be a great start! I wonder if it would also make sense to fold #765 and #570 and this into a single issue (or, rather just pick one and close the other two?) That'd would help the conversation around this be less fragmented.

shonfeder commented 3 years ago

In case it's useful context, I was considering using an embedable prolog as an alternative to sqlite (nice properties, like being able to write the database to a file in a readable way, and commit that to git, easily defining transitive closures, etc.). Of course, I could communicate through system calls, and manually implement de/serialization for data etc., but that's more over-head and requires an external dependency.

ghost commented 3 years ago

Making a new issue to track the progress once all the others are closed is a possibility to better organize. For now the library doesn't exist yet.

Immortalin commented 3 years ago

And a two-way FFI would be very useful too.

XVilka commented 3 years ago

A heads up for anyone subscribed to this issue - the initial work is here https://github.com/mthom/scryer-prolog/pull/838

peschue commented 2 years ago

@triska I performed some initial experiments to communicate via scryer-prolog via STDIO or TTY - in both cases I encountered some difficulties, one case might even be a bug (the panic that happens with STDIO) see details here: https://github.com/mthom/scryer-prolog/discussions/1413

triska commented 2 years ago

@peschue: If Scryer crashes, then this is definitely a mistake somewhere in the code, please consider filing it as an issue with a minimal example, which ideally only needs a shell invocation or pipe on the command line. Thank you a lot!

peschue commented 2 years ago

@triska I created issue https://github.com/mthom/scryer-prolog/issues/1439 for this.

triska commented 1 year ago

There is a very promising contribution with the potential to resolve what remains of this issue: #1880.

Please try it and comment if possible!

triska commented 10 months ago

@uraj: #1880 is now merged and I think it solves this issue. If it solves the issue for you, could you please consider closing it? Thank you a lot!

uraj commented 10 months ago

@triska I think this works. Thanks everyone for working on this over the years. Closing.

jjtolton commented 1 month ago

I can't tell if this has already been done or not, but I wasn't able to figure it out, so I hacked together some bindings that make it fairly straightforward to use scryer as a shared library: https://github.com/mthom/scryer-prolog/pull/2465

This might be a sequel to #1880, but I'm not really sure.