This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/python/swig/jupyter.yap

33 lines
757 B
Plaintext
Raw Normal View History

2017-06-08 08:50:37 +01:00
:- use_module(library(python)).
:- use_module(library(yapi)).
:- python_import(sys).
set_python_output(OldOutput,OldError) :-
open('//python/sys.stdout', append, Output),
open('//python/sys.stderr', append, Error),
prolog_flag(user_output, OldOutput, Output),
prolog_flag(user_error, OldError, Error).
restore_python_output(OldOutput,OldError) :-
set_prolog_flag(user_output, Output),
set_prolog_flag(user_error, Error),
prolog_flag(user_output, OldOutput, Output),
prolog_flag(user_error, OldError, Error),
close(OldOutput),
close(OldError).
2017-06-12 18:02:37 +01:00
jupyter_query(String, Dict ) :-
set_python_output(OldOutput,OldError),
writeln(my:String),
yapi_query( String, Dict),
writeln(my:Dict),
restore_python_output(OldOutput,OldError),
2017-06-08 08:50:37 +01:00
true.