This commit is contained in:
Vitor Santos Costa 2017-06-12 18:02:37 +01:00
parent 732adf9f43
commit ea099c83bb
4 changed files with 17 additions and 42 deletions

View File

@ -12,14 +12,9 @@ include(CMakeToolsHelpers OPTIONAL)
project( YAP ) project( YAP )
if (ANDROID) set(YAP_APP_DIR "${CMAKE_SOURCE_DIR}/../..")
set(YAP_APP_DIR "${CMAKE_SOURCE_DIR}/../..")
cmake_policy(VERSION 3.4) cmake_policy(VERSION 3.4)
else ()
cmake_minimum_required(VERSION 2.8)
endif()
set( set(
CMAKE_MODULE_PATH CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}"

View File

@ -731,7 +731,8 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
Py_INCREF(typp); Py_INCREF(typp);
} }
o = PyStructSequence_New(typp); o = PyStructSequence_New(typp);
for (arity_t i = 0; i < arity; i++) { arity_t i;
for (i=0; i < arity; i++) {
PyObject *pArg = PyTuple_GET_ITEM(tuple, i); PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
Py_INCREF(pArg); Py_INCREF(pArg);
if (pArg) if (pArg)

View File

@ -23,10 +23,10 @@ restore_python_output(OldOutput,OldError) :-
close(OldOutput), close(OldOutput),
close(OldError). close(OldError).
jupyter_query( VarNames, Dict ) :- jupyter_query(String, Dict ) :-
%set_python_output(OldOutput,OldError), set_python_output(OldOutput,OldError),
writeln(my:String), writeln(my:String),
show_answer( VarNames, user_error, Dict), yapi_query( String, Dict),
writeln(my:VarNames), writeln(my:Dict),
%restore_python_output(OldOutput,OldError). restore_python_output(OldOutput,OldError),
true. true.

View File

@ -39,7 +39,7 @@ from IPython.core import oinspect
from IPython.core import magic from IPython.core import magic
from IPython.core import page from IPython.core import page
from IPython.core import prefilter from IPython.core import prefilter
from IPython.core import shadowns # from IPython.core import shadows
from IPython.core import ultratb from IPython.core import ultratb
from IPython.core import interactiveshell from IPython.core import interactiveshell
from IPython.core.alias import Alias, AliasManager from IPython.core.alias import Alias, AliasManager
@ -168,12 +168,12 @@ rquwer
result.execution_count = self.shell.execution_count result.execution_count = self.shell.execution_count
try: try:
if self.q = query_prolog(s): if self.q == jupyter_query(s, Dict):
self.shell.last_execution_succeeded = True self.shell.last_execution_succeeded = True
result.result = True result.result = (True, Dict)
else: else:
self.shell.last_execution_succeeded = True self.shell.last_execution_succeeded = True
result.result = True result.result = (True, {})
except Exception as e: except Exception as e:
print(e) print(e)
self.shell.last_execution_succeeded = False self.shell.last_execution_succeeded = False
@ -208,12 +208,12 @@ rquwer
# #
# construct a query from a one-line string # construct a query from a one-line string
# q is opaque to Python # q is opaque to Python
q = engine.query(s) q = jupyter_query(s,dict)
# vs is the list of variables # vs is the list of variables
# you can print it out, the left-side is the variable name, # you can print it out, the left-side is the variable name,
# the right side wraps a handle to a variable # the right side wraps a handle to a variable
# pdb.set_trace() # pdb.set_trace()
vs = q.namedVarsVector() #vs = q.namedVarsVector()
#pdb.set_trace() #pdb.set_trace()
# atom match either symbols, or if no symbol exists, sttrings, In this case # atom match either symbols, or if no symbol exists, sttrings, In this case
# variable names should match strings # variable names should match strings
@ -225,26 +225,5 @@ rquwer
# launch the query # launch the query
while answer(q): while answer(q):
# this new vs should contain bindings to vars # this new vs should contain bindings to vars
vs= q.namedVars() print( dict )
print( vs )
gs = numbervars( engine, vs)
print(gs)
i=0
# iterate
for eq in gs:
name = eq[0]
binding = eq[1]
# this is tricky, we're going to bind the variables in the term so thay we can
# output X=Y. The Python way is to use dictionares.
#Instead, we use the T function to tranform the Python term back to Prolog
if name != binding:
print(name + " = " + str(binding))
#ok, that was Prolog code
print("yes")
# deterministic = one solution
if q.deterministic():
# done
q.close()
return
q.close()
return