1

I was trying to use pyswip to create a Q&A (interactive user) python swi-prolog program and I couldn't find a good way to read/write from/to pyswip using python flask. The app is originally a web application and I'm using flask to run the python code.

I have a function that asks a question to the user defined as follows:

def question(Question):
  print 'Does it have the following attributes: ', Question,'?'
  Response = raw_input()
  if Response == 'yes' or Response == 'y':
    return True
  else:
    return False

The question function is defined as a foreign function with arity 1 so in prolog I have this:

registerForeign(question,name='ask', arity=1)
prolog.assertz("verify(S) :- (yes(S) -> true ;(no(S) -> fail ;(ask(S) -> assert(yes(S)); assert(no(S)), fail)))")

Note ask(S) in the assertz that is the call to the question function I have, now I need to change the arity of question function to 2:

registerForeign(question,name='ask', arity=2) 
question(Question, userInput) 

where userInput is the python raw_input parser that should read the user's input and if you look at the question function you will notice that it used to be done inside the function itself.

Any thoughts on how I can change the prolog part accordingly?

Rihab
  • 7
  • 7

0 Answers0