Search code examples
prologinstantiation-error

Arguments not sufficiently instantiated when consulting file


I'm running SWI-Prolog on a Mac through the Terminal. I'm trying to access an Atom file by writing the usual after opening up swipl in the terminal:

?- [hwk1-my_name].

Instead of swipl having the knowledge base to play with, it's giving me this:

ERROR: Arguments are not sufficiently instantiated

I'm new to Prolog, and my program as it stands now is simply the copied-and-pasted code provided by my professor to get the assignment started. Does this mean that the error is likely due to something within the code below, and if so, what is prompting this? Here is the code provided to me:

father(Dad, Child) :-
   parent(Dad, Child),
   male(Dad).

mother(Mom, Child) :-
   parent(Mom, Child),
   female(Mom).

had_a_child(Man, Woman) :-
   father(Man, Child),
   mother(Woman, Child).

sibling(Sibling1, Sibling2) :-
   parent(Parent, Sibling1),
   parent(Parent, Sibling2),
   Sibling1 \= Sibling2.

brother(Brother, Sib) :-
   sibling(Brother, Sib),
   male(Brother).

sister(Sister, Sib) :-
   sibling(Sister, Sib),
   female(Sister).

Solution

  • Your obvious problem is the - inside the file name. The text editor you are using is completely irrelevant. Even confusing, as one of Prolog's data types is the atom.

    You have two options:

    1. Use file names that would be valid Prolog atoms even without quoting. This means that they cannot start with a capital or a digit, and can contain only letters, digits, and underscores (_). Then, your file can still have the .pl extension and you can consult it like you do: foo.pl ---> ?- [foo].

    2. Use the complete filename, extension included, and put single quotes around it: foo-bar.baz ---> ?- ['foo-bar.baz'].. As you will see, you don't even need the .pl extension any more.

    Whenever you are in doubt about what Prolog sees, you can try write_canonical/1:

    ?- write_canonical(hwk1-my_name).
    -(hwk1, my_name)
    true.
    

    In other words, Prolog takes this as the compound term -/2 with the atoms hwk1 and my_name as the first and second argument.