Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading files in Prolog

Tags:

prolog

I am going through a Prolog tutorial. It is telling me I can load other prolog files by typing:

[filename].

but every time I try this am getting

ERROR: load_files/2: Arguments are not sufficiently instantiated.

The file is in the same directory as the one am working in.

Here is a copy of the entire query and error:

12 ?- [KB5].

ERROR: load_files/2: Arguments are not sufficiently instantiated

What am I doing wrong?

like image 955
cubearth Avatar asked Dec 21 '10 03:12

cubearth


People also ask

How do I load a file in Prolog?

Open a terminal (Ctrl+Alt+T) and navigate to the directory where you stored your program. Open SWI-Prolog by invoking swipl . In SWI-Prolog, type [program] to load the program, i.e. the file name in brackets, but without the ending. In order to query the loaded program, type goals and watch the output.

How do I load a rule in Prolog?

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

Where are Prolog files saved?

You save your file by using the Save option from the File menu on the menu bar at the top of the editor's window, making sure you save it at the root level of your M drive. Make sure that you give your Prolog files the extension . pl .

How do you consult in Prolog?

These programs are written using an editor, and read into the Prolog interpreter. The process of reading programs into Prolog is known as consulting. Most Prologs include a built-in predicate called consult/1. (Some older Prologs have two versions consult/1 and reconsult/1 which have to be used at different times.


2 Answers

$ cat junk.pl
test(ok).

$ prolog
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.8.0)
Copyright (c) 1990-2009 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [junk].
% junk compiled 0.00 sec, 24 bytes
true.

It seems to work fine for me. Of course I'm using an atom for my file name, not a variable. (KB5 is a variable name, not an atom.) First try ['KB5'] and see if that helps. Next try [kb5] and see if that helps. Finally try an absolute minimal example like the one I provided and see if you can load that way.


Edited to add:

$ cp junk.pl JUNK.pl
$ prolog
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.8.0)
Copyright (c) 1990-2009 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [JUNK].
ERROR: load_files/2: Arguments are not sufficiently instantiated
?- ['JUNK'].
% JUNK compiled 0.00 sec, 1,656 bytes
true.

It looks like the atom problem indeed. Use ['KB5'] and your error will probably go away.

like image 81
JUST MY correct OPINION Avatar answered Oct 14 '22 09:10

JUST MY correct OPINION


Although the other method provided works. Here is an alternative:

?- consult('C:/User/Folder/myRules.pl').

That should do the trick!

like image 20
Scott Gramig Avatar answered Oct 14 '22 08:10

Scott Gramig