Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to write prolog programs how to run prolog?


Asked by Vincent Greer on Dec 10, 2021 FAQ



How to run Prolog How to write Prolog programs Built-in predicates: Input predicates--read, get, get0, see, seen. Output predicates--write, writeq, tab, nl, put, tell, told. Control predicates--X ; Y, (X -> Y), (X -> Y ; Z), not X, true, repeat, fail, !, abort.
Subsequently,
--goal: This is basically to help prolog determine the exit code of the program. I'm using the output from the main predicate. This also clues prolog in on what predicate to start with so it will run main. Without this, when your program runs you'll get a prolog prompt and you will have to type in main with is not what we want.
In respect to this, Start writing a Prolog program in a file with extension .pl. If your program consists of multiple files, it is common practice to add a file load.pl that contains file-loading directives to load the various parts of the program: /* File: load.pl Purpose: Load my program */ :- [ rules, inference, goals ].
Furthermore,
There's no official standard for the Prolog built-in predicates that compile and load a source file. The most common ones are consult (File), reconsult (File), and load_files (Files, Options). The shortcut [File| Files] is also often available. You will need to consult the documentation of the Prolog system you're using.
Next,
Now let us see how to run the Prolog script file (extension is *.pl) into the Prolog console. Before running *.pl file, we must store the file into the directory where the GNU prolog console is pointing, otherwise just change the directory by the following steps − Step 1 − From the prolog console, go to File > Change Dir, then click on that menu.