3

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).
false
  • 10,264
  • 13
  • 101
  • 209
quantumferret
  • 473
  • 6
  • 12
  • 2
    Also check this out: If your professor had used the name `father_of/2` instead of just `father/2`, it would have been clear which argument actually denotes the father! – mat Feb 05 '16 at 08:05
  • @WillNess. Adding a tag for insufficient instantiation is good, but I wonder if `non-instantiated-argument` is a good tag name... Personally, I'd **much** prefer `instantiation-error` and `uninstantiation-error` (cf. https://www.complang.tuwien.ac.at/ulrich/iso-prolog/error_k)! These are used in [tag:iso-prolog] and they tell the expected property (e.g. `uninstantiation`) whose absense lead to an `error`. – repeat Feb 06 '16 at 13:20
  • @mat. What's your point of view on this new tag thingy? – repeat Feb 06 '16 at 13:25
  • @false. Which names do you recommend? I checked and both alternatives are still unused on SO, IIRC. – repeat Feb 06 '16 at 13:26
  • @repeat whatever you guys decide is fine with me. I won't tag any more questions for now. :) – Will Ness Feb 06 '16 at 13:46
  • 1
    @WillNess. Rest assured that I didn't want to put you down by dissing the tag you proposed—quite the opposite: **Thank you** for taking the initiative and get the ball rolling! Please stay in the discussion. How about posting a question on meta.SO about that tag name finding mission? (Is meta.SO the right place?) – repeat Feb 06 '16 at 14:44
  • @repeat Thanks; I wasn't, and put the smiley to signify that; but you're completely right and thank you for clarifying this, as "the written communication is notoriously prone to misunderstandings". :) The fault is with me for being too laconic. – Will Ness Feb 06 '16 at 16:12
  • @repeat [done](http://meta.stackoverflow.com/q/316334/849891). – Will Ness Feb 06 '16 at 16:18
  • @repeat and I'm getting hammered for it. :) I *hate* meta. I remember now why I always try to avoid it. :) – Will Ness Feb 06 '16 at 16:38
  • 2
    I definitely agree with Will Ness and you that a tag for this is good. `instantiation-error` would be a good name. `uninstantiation-error` denotes the opposite, i.e., **too much** instantiation, and the fact that **less** (i.e., "un") instantiation is expected. Many users with "Arguments are not sufficiently instantiated" questions encounter them in connection with arithmetic (mostly integers) and hugely benefit from being told about **CLP(FD)**, so in some of these questions, I have also added the [tag:clpfd] tag together with a response that shows how to solve the issue with pure methods. – mat Feb 06 '16 at 18:56

1 Answers1

6

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.

  • Thank you very much! Problem fixed. – quantumferret Feb 05 '16 at 08:16
  • 1
    @quantumferret Happy to help. I am certain that your question is a duplicate, as this problem pops up often enough. I will edit your title to make it easier to find. –  Feb 05 '16 at 08:24
  • Yeah I wasn't sure of the terminology to use. Now that the question is up I'm seeing possible duplicates in the 'Related' section :/ – quantumferret Feb 05 '16 at 08:26
  • @quantumferret Don't worry, the error message is a bit inscrutable. A more informative error message would definitely be helpful in this place. –  Feb 05 '16 at 08:28
  • 1
    as expected: `?- [hwk1-my_name]. ERROR: Type error: \`file_path' expected, found \`hwk1-my_name' (a compound)`. I wonder if OP's problem was really what has been reported. – CapelliC Feb 05 '16 at 16:35
  • 1
    @CapelliC older version. I remember getting this very error some time ago: can't remember when. –  Feb 05 '16 at 17:41
  • @Boris: Even in 5.10.4 there is a type error. Even for `[A-B].` – false Feb 07 '16 at 22:23
  • @false you are correct, I couldn't reproduce that error. I have faint and possibly false memories of getting a confusing error message when trying to consult files with strange names. I guess it is up to OP to reproduce their problem (but they claim "problem fixed"). I don't know how to help without creating more confusion at that point. –  Feb 08 '16 at 08:37