scryer-prolog icon indicating copy to clipboard operation
scryer-prolog copied to clipboard

scryper-prolog as a library

Open uraj opened this issue 6 years ago • 15 comments

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.

uraj avatar Oct 29 '19 18:10 uraj

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.

triska avatar Oct 29 '19 22:10 triska

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.

uraj avatar Oct 29 '19 23:10 uraj

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.

mthom avatar Oct 30 '19 14:10 mthom

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.

Immortalin avatar Nov 08 '19 03:11 Immortalin

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.

hashedone avatar Nov 27 '19 08:11 hashedone

I came in search of this this too.

shonfeder avatar Feb 25 '21 01:02 shonfeder

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, ...

ghost avatar Feb 25 '21 15:02 ghost

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 avatar Feb 25 '21 16:02 shonfeder

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.

shonfeder avatar Feb 25 '21 16:02 shonfeder

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.

ghost avatar Feb 25 '21 16:02 ghost

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

Immortalin avatar Feb 25 '21 17:02 Immortalin

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

XVilka avatar Aug 20 '21 07:08 XVilka

@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

peschue avatar Apr 21 '22 19:04 peschue

@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!

triska avatar Apr 21 '22 19:04 triska

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

peschue avatar Apr 21 '22 20:04 peschue

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 avatar Jul 12 '23 20:07 triska

@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!

triska avatar Nov 22 '23 19:11 triska

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

uraj avatar Nov 22 '23 23:11 uraj