1

I'm trying to have the user input their birthday so I can tell them their zodiac sign. However, I'm having trouble getting their actual birthday and month. Could someone please help me? I've tried separating the reads into different functors, but I keep getting errors. The error I get when I combine both reads is "Syntax error: Operator priority clash." The error I get when I separate both reads is "ERROR: =:=/2: Arguments are not sufficiently instantiated."

Code when I combine the reads:

start :-
   read_month,

read_month :-
   write('Enter your birth month (month followed by a .): '),
   nl,
   read(X),
   write('Enter your day of birth (followed by a .): '),
   nl,
   read(Y),
   horoscope(X,Y).

Code when I separate the reads:

start :-
   read_month,
   read_day.

read_month :-
   write('Enter your birth month (month followed by a .): '),
   nl,
   read(X).

read_day :-
   write('Enter your day of birth (followed by a .): '),
   nl,
   read(Y),
   horoscope(X,Y).
false
  • 10,264
  • 13
  • 101
  • 209
mylasthope
  • 89
  • 7

1 Answers1

3

As a beginner, do not start like that. (And your first program is syntactically incorrect ; the first rule does not end with a period).

Instead, write a relation month_day_sign/3 which you can use directly at the toplevel, like so:

?- month_day_sign(7,24,Sign).
   Sign = leo.

That's the way how you normally interact with Prolog. So you are exploiting the functionality of the toplevel shell.

Once you have mastered this, you may make some extra interface around. But don't go the other way!


By separating both "actions", the X is now disconnected from horoscope(X,Y)...

false
  • 10,264
  • 13
  • 101
  • 209
  • downvoted, as this doesn't answer the question. This answer would have made a good comment or side note with an answer to the actual question. – Xaser Nov 03 '17 at 05:57
  • 1
    @Xaser, accidentally saw this question and your comment, the answer provided is better-optimized approach than what asked and also accepted from op, so how this doesn't answer the question (since it's accepted)?? – coder Nov 03 '17 at 17:37
  • @coder, the answer probably got accepted because the OP was happy with the solution provided, even though it doesn't do what he initially intended to do.. However there are many others coming across this question on google, for who the provided alternative is not viable and they still seek a way to accomplish what the question asked for (i.e. work with proper terminal queries). – Xaser Nov 04 '17 at 02:55