Merge branch 'master' of ssh://ssh.dcc.fc.up.pt:31064/home/vsc/yap
This commit is contained in:
@@ -73,8 +73,9 @@ python_query( Caller, String ) :-
|
||||
query_to_answer( Goal, VarNames, Status, Bindings),
|
||||
Caller.port := Status,
|
||||
write_query_answer( Bindings ),
|
||||
nl(user_error),
|
||||
maplist(in_dict(Caller.answer, Bindings), Bindings).
|
||||
nl(user_error),
|
||||
maplist(in_dict(Caller.answer, Bindings), Bindings).
|
||||
>>>>>>> 37d5dcedc17b8c63cd9fa213454edb37816a130f
|
||||
|
||||
/**
|
||||
*
|
||||
|
@@ -78,16 +78,20 @@ class Query (YAPQuery):
|
||||
super().__init__(g)
|
||||
self.engine = engine
|
||||
self.port = "call"
|
||||
self.bindings = None
|
||||
self.answer = {}
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def done(self):
|
||||
return self.port == "fail" or self.port == "exit"
|
||||
|
||||
def __next__(self):
|
||||
if self.port == "fail":
|
||||
raise IndexError()
|
||||
return self.next()
|
||||
self.answer = {}
|
||||
if self.port == "fail" or self.port == "exit":
|
||||
raise StopIteration()
|
||||
if self.next():
|
||||
return self.answer
|
||||
raise StopIteration()
|
||||
|
||||
def name( name, arity):
|
||||
try:
|
||||
@@ -141,7 +145,7 @@ class YAPShell:
|
||||
# # vs is the list of variables
|
||||
# you can print it out, the left-side is the variable name,
|
||||
# the right side wraps a handle to a variable
|
||||
import pdb; pdb.set_trace()
|
||||
# import pdb; pdb.set_trace()
|
||||
# #pdb.set_trace()
|
||||
# atom match either symbols, or if no symbol exists, sttrings, In this case
|
||||
# variable names should match strings
|
||||
@@ -151,14 +155,13 @@ class YAPShell:
|
||||
# return
|
||||
try:
|
||||
engine = self.engine
|
||||
bindings = []
|
||||
bindings = []
|
||||
loop = False
|
||||
g = python_query(self, query)
|
||||
self.q = Query( engine, g )
|
||||
while self.q.next():
|
||||
bindings += [self.q.answer]
|
||||
if self.q.port == "exit":
|
||||
break
|
||||
q = Query( engine, python_query( engine, query) )
|
||||
for answer in q:
|
||||
bindings += [answer]
|
||||
if g.done():
|
||||
return bindings
|
||||
if loop:
|
||||
continue
|
||||
s = input("more(;), all(*), no(\\n), python(#)? ").lstrip()
|
||||
@@ -177,10 +180,8 @@ class YAPShell:
|
||||
if self.q:
|
||||
self.q.close()
|
||||
self.q = None
|
||||
if bindings:
|
||||
return True,bindings
|
||||
print("No (more) answers")
|
||||
return False, None
|
||||
return bindings
|
||||
except Exception as e:
|
||||
if not self.q:
|
||||
return False, None
|
||||
|
@@ -42,7 +42,7 @@ jupyter_cell(Caller, _, Line ) :-
|
||||
catch(
|
||||
python_query(Query,Line),
|
||||
error(A,B),
|
||||
system_error(A,B)
|
||||
(writeln(A,B),system_error(A,B))
|
||||
).
|
||||
|
||||
restreams(call) :-
|
||||
|
@@ -550,7 +550,7 @@ class YAPRun(InteractiveShell):
|
||||
self.yapeng.mgoal(errors(self,text),"user",True)
|
||||
return self.errors
|
||||
|
||||
def jupyter_query(self, s):
|
||||
def prolog(self, s):
|
||||
#
|
||||
# construct a self.queryuery from a one-line string
|
||||
# self.query is opaque to Python
|
||||
@@ -590,7 +590,7 @@ class YAPRun(InteractiveShell):
|
||||
if found:
|
||||
sys.stderr.write('Completed, with '+str(self.answers)+'\n')
|
||||
result.result = self.answers
|
||||
return result
|
||||
return result.results
|
||||
|
||||
except Exception as e:
|
||||
sys.stderr.write('Exception '+str(e)+'in query '+ str(self.query)+
|
||||
@@ -736,7 +736,7 @@ class YAPRun(InteractiveShell):
|
||||
# run the new command using the given tracer
|
||||
#
|
||||
# tracer.runfunc(f,self,cell,state)
|
||||
self.jupyter_query( cell )
|
||||
self.prolog( cell )
|
||||
# state = tracer.runfunc(jupyter_query( self, cell ) )
|
||||
self.shell.last_execution_succeeded = True
|
||||
result.result = []
|
||||
@@ -814,12 +814,15 @@ class YAPRun(InteractiveShell):
|
||||
If the line terminates on a `*/` or starts on a `%` we assume the line
|
||||
is a comment.
|
||||
"""
|
||||
s0 = s.rstrip(' \n\t\i')
|
||||
[program,x,query] = s0.rpartition('\n')
|
||||
if query[-1] == '.':
|
||||
return s,'',False,0
|
||||
(query, _,loop, sols) = self.clean_end(query)
|
||||
return (program, query, loop, sols)
|
||||
try:
|
||||
s0 = s.rstrip(' \n\t\i')
|
||||
[program,x,query] = s0.rpartition('\n')
|
||||
if query[-1] == '.':
|
||||
return s,'',False,0
|
||||
(query, _,loop, sols) = self.clean_end(query)
|
||||
return (program, query, loop, sols)
|
||||
except:
|
||||
return (s,'',true,1)
|
||||
|
||||
# global
|
||||
#globals = {}
|
||||
|
Reference in New Issue
Block a user