FYI
Since you note im a newbie to prolog
and this is actually more of a second semester entire semester project than a first semester chapter exercise this will take some time to understand; here are some pointers.
- The SWI-Prolog documentation is not written to give examples. It notes
This document is a reference manual . That means that it documents the system, but it does not explain the basics of the Prolog language and it leaves many details of the syntax, semantics and built-in primitives undefined where SWI-Prolog follows the standards. This manual is intended for people that are familiar with Prolog.
So don’t expect to find working code examples in the documentation.
Note: I use dark mode which makes the next two images very hard to see. To see them I right click on them and open in a new browser tab.
you will most likely be working and living in the code from the http libraries. (ref)
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_server_files)).
:- use_module(library(http/http_files)).
:- use_module(library(pengines)).
:- use_module(pengine_sandbox:library(pengines)).
-
I find that seeing working examples is one of the best ways to understand the code. The best way I know to find working examples is to
a. Look for examples in the supplied code. pengine has an example directory. (examples)
b. Look for others who have published code on GitHub. The key to find such code is to search for a word that is unique.
pengines - pengine_create/1 (GitHub search).
web sockets - ws_receive/2 (GitHub search).
For going lower into code I like to search the library http_dispatch (GitHub search)
Understand that code in the wild my be good as an example or may be horrible as an example. It is a learned skill to know which. List of GitHub accounts with quality Prolog code. -
Ask questions here. While you can ask on StackOverflow, StackOverflow is not really a great place to solve a problem that may need a discussion. Also it is better to ask than not to ask. The worse that can happen is that your question will not get answered. Even my questions sometimes don’t get any reply, don’t take it personally.
-
Expect to be very frustrated often and for a long time, a week or more. Remeber that one learns more from failure than success.
“The master has failed more times than the beginner has even tried.” - Stephen McCranie
-
If you use machine query interface realize that it is only a few months old (ref) and I don’t know of any other examples than the one by the creator (Eric Zinda). If you choose this odds are we will be learning more from you about MQI but you will be learning Prolog from us.
-
Don’t get bogged down in premature optimization. Get the code working correctly first, no matter how bad the code looks and/or how in effective the data structures are, then once you have it all working correctly focus on optimizations. Intel even expands on this idea. (ref)
HTH