0

I have an assert query that is something like:

:- dynamic a/1,b/1.

dump:- listing(a),listing(b).

main:-retractall(a(X)),assert(a(1):-write('aa')),
      retractall(b(X)),assert(b(1):-write('bb')).

I want the user to type a(1) or b(1), the program to display aa or bb respectively (so far so good) and then to call another procedure,depending on what the user has typed.

For instance, if he typed a(1), I want a procedure called pro_a to run, and respectively if he types b(1), a procedure pro_b will run

These procedures will be:

  pro_a:- retractall(a(X)),retractall(b(X)),write('you chose a'),
          assert(a(1):-write('aa1')).

  pro_b:- retractall(a(X)),retractall(b(X)),write('you chose b'),
          assert(b(1):-write('bb1')).

and so on.

What I tried is something like:

assert(a(1):-write('aa'),pro_a).

But that doesn't work. Is assert supposed to have only one command? (I'm not sure how to explain this).

false
  • 10,264
  • 13
  • 101
  • 209
Shevliaskovic
  • 1,562
  • 4
  • 26
  • 43
  • 3
    You need an extra set of parentheses: `assert((a(1):-write('aa'),pro_a)).` – lurker Nov 09 '13 at 12:44
  • Perfect! Thanks. Do I need to add an extra set of parentheses for every procedure? – Shevliaskovic Nov 09 '13 at 13:04
  • No, the assert needs it because of the operator precedence of `:-`. If you were asserting a simple fact, for example, it would just be `assert(foo(1)).`. – lurker Nov 09 '13 at 13:44
  • Yeah,but if i wanted to run pro_a and pro_b, would it be like `assert(((a(1):-write('aa'),pro_a),pro_b)).` ? – Shevliaskovic Nov 09 '13 at 13:56
  • That would be an error since the form of what you wrote is `assert((..., ...)).` so it is attempting to redefine `,`. – lurker Nov 09 '13 at 14:28

0 Answers0