Skip to content

Commit

Permalink
Add jupyter::versions/0 predicate and versions line magic
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoura committed Sep 26, 2023
1 parent 3a1d126 commit b890fbc
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 28 deletions.
41 changes: 37 additions & 4 deletions logtalk_kernel/logtalk_server/jupyter.lgt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:- object(jupyter).

:- info([
version is 0:3:1,
version is 0:4:0,
author is 'Anne Brecklinghaus, Michael Leuschel, and Paulo Moura',
date is 2023-09-26,
comment is 'This object provides special predicates which can be used in call requests by the client. Some of these predicates need to be the only goal of a query. Otherwise, they cannot be determined as special predicates and do not work as expected.'
Expand All @@ -55,7 +55,8 @@
trace/1, % trace(+Goal)
update_completion_data/0,
version/4,
version/0
version/0,
versions/0
]).

:- uses(debugger, [leash/1, trace/0, notrace/0]).
Expand All @@ -71,7 +72,32 @@
version :-
version(Major, Minor, Patch, Status),
%log('Version ~w.~w.~w-~w~n',[Maj,Min,Patch,Status]),
format('Version ~w.~w.~w-~w of Jupyter-Logtalk-Kernel~n', [Major, Minor, Patch, Status]).
format('Logtalk Jupyter kernel ~w.~w.~w-~w~n', [Major, Minor, Patch, Status]).

versions :-
current_logtalk_flag(version_data, logtalk(LogtalkMajor, LogtalkMinor, LogtalkPatch, LogtalkStatus)),
format('Logtalk ~w.~w.~w-~w~n', [LogtalkMajor, LogtalkMinor, LogtalkPatch, LogtalkStatus]),
current_logtalk_flag(prolog_dialect, Backend),
backend(Backend, BackendName),
current_logtalk_flag(prolog_version, v(BackendMajor, BackendMinor, BackendPatch)),
format('~w ~w.~w.~w~n', [BackendName, BackendMajor, BackendMinor, BackendPatch]),
version.

backend(b, 'B-Prolog').
backend(ciao, 'Ciao Prolog').
backend(cx, 'CxProlog').
backend(eclipse, 'ECLiPSe').
backend(gnu, 'GNU Prolog').
backend(ji, 'JIProlog').
backend(lvm, 'LVM').
backend(quintus, 'Quintus Prolog').
backend(scryer, 'Scryer Prolog').
backend(sicstus, 'SICStus Prolog').
backend(swi, 'SWI-Prolog').
backend(tau, 'Tau Prolog').
backend(trealla, 'Trealla Prolog').
backend(xsb, 'XSB').
backend(yap, 'YAP').

% Help

Expand Down Expand Up @@ -119,7 +145,9 @@
format(' %queries~n', []),
format(' Prints previous queries~n~n', []),
format(' %help~n', []),
format(' Prints documentation for all predicates from object jupyter~n~n', []),
format(' Prints documentation for all predicates from object jupyter~n', []),
format(' %versions~n', []),
format(' Prints Logtalk, Prolog backend, and Jupyter kernel versions~n~n', []),
format(' %magic~n', []),
format(' Prints help in using cell and line magic~n', []).

Expand All @@ -137,6 +165,11 @@
'jupyter::help',
'\n\n Outputs the documentation for all predicates from object jupyter.'
], Doc).
predicate_doc('jupyter::versions/0', Doc) :-
atomic_list_concat([
'jupyter::versions',
'\n\n Prints Logtalk, Prolog backend, and Jupyter kernel versions.'
], Doc).
predicate_doc('jupyter::magic/0', Doc) :-
atomic_list_concat([
'jupyter::magic',
Expand Down
2 changes: 1 addition & 1 deletion logtalk_kernel/logtalk_server/jupyter_preferences.lgt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
print_message(debug, jupyter, Message) as dbg(Message)
]).

version(0, 6, 2, 'beta').
version(0, 7, 0, 'beta').

preference_definition(verbosity, 1, natural, 'Verbosity level, 0=off, 10=maximal').

Expand Down
5 changes: 3 additions & 2 deletions logtalk_kernel/logtalk_server/jupyter_request_handling.lgt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
:- object(jupyter_request_handling).

:- info([
version is 0:3:0,
version is 0:4:0,
author is 'Anne Brecklinghaus, Michael Leuschel, and Paulo Moura',
date is 2023-09-25,
date is 2023-09-26,
comment is 'This object provides predicates to start a loop reading and handling JSON RPC requests.'
]).

Expand Down Expand Up @@ -340,6 +340,7 @@
line_cell_magic('%bindings', 'jupyter::print_variable_bindings.').
line_cell_magic('%queries', 'jupyter::print_queries.').
line_cell_magic('%help', 'jupyter::help.').
line_cell_magic('%versions', 'jupyter::versions.').
line_cell_magic('%magic', 'jupyter::magic.').

:- end_object.
46 changes: 31 additions & 15 deletions notebooks/JupyterKernelForLogtalkOverview.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"\n",
"The default backend can be changed in the fly by adding a code cell at the top and running one of the following queries: `eclipse`, `gnu`, `lvm`, `sicstus`, `trealla`, or `yap`. The default backend can be set for all notebooks in a directory by using a `logtalk_kernel_config.py` file (see the [logtalk-jupyter-kernel](https://github.com/LogtalkDotOrg/logtalk-jupyter-kernel) repo for details). If this file is not present, the default backend is SWI-Prolog.\n",
"\n",
"This Logtalk notebook is currently using the following Prolog backend:"
"This notebook is currently running using:"
]
},
{
Expand All @@ -31,16 +31,26 @@
{
"data": {
"text/plain": [
"\u001b[1mBackend = swi,\n",
"Version = v(9,1,16)"
"Logtalk 3.71.0-b01\n",
"SWI-Prolog 9.1.16\n",
"Logtalk Jupyter kernel 0.7.0-beta"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"\u001b[1mtrue"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"current_logtalk_flag(prolog_dialect, Backend), current_logtalk_flag(prolog_version, Version)."
"%versions"
]
},
{
Expand Down Expand Up @@ -169,8 +179,6 @@
{
"data": {
"text/plain": [
"$Backend = swi\n",
"$Version = v(9,1,16)\n",
"$VersionData = logtalk(3,71,0,b01)\n",
"$X = [1,2,3]\n",
"$Z = [1,2,3,4,5,6]\n",
Expand Down Expand Up @@ -257,7 +265,7 @@
{
"data": {
"text/plain": [
"current_logtalk_flag(prolog_dialect,Backend),current_logtalk_flag(prolog_version,Version),\n",
"jupyter::versions,\n",
"current_logtalk_flag(version_data,VersionData),\n",
"X=[1,2,3],list::append(X,[4,5,6],Z),\n",
"current_logtalk_flag(unicode,Unicode),\n",
Expand Down Expand Up @@ -849,8 +857,8 @@
{
"data": {
"text/plain": [
" Call: (1) fred::number_of_legs(_18232)\n",
" Call: (2) number_of_legs(_18232)\n",
" Call: (1) fred::number_of_legs(_18032)\n",
" Call: (2) number_of_legs(_18032)\n",
" Fact: (2) number_of_legs(4)\n",
" Exit: (2) number_of_legs(4)\n",
" Exit: (1) fred::number_of_legs(4)"
Expand Down Expand Up @@ -929,14 +937,14 @@
"data": {
"text/plain": [
"% \n",
"% tests started at 2023-09-26, 12:27:21\n",
"% tests started at 2023-09-26, 15:45:51\n",
"% \n",
"% running tests from object tests\n",
"% file: /Users/pmoura/logtalk/examples/ack/tests.lgt\n",
"% \n",
"% ack_1: success (in 0.001846000 seconds)\n",
"% ack_2: success (in 0.065044000 seconds)\n",
"% ack_3: success (in 0.276049000 seconds)\n",
"% ack_1: success (in 0.001745000 seconds)\n",
"% ack_2: success (in 0.062015000 seconds)\n",
"% ack_3: success (in 0.264898000 seconds)\n",
"% \n",
"% 3 tests: 0 skipped, 3 passed, 0 failed (0 flaky)\n",
"% completed tests from object tests\n",
Expand All @@ -951,7 +959,7 @@
"% 1 out of 1 entity covered, 100.000000% entity coverage\n",
"% 3 out of 3 clauses covered, 100.000000% clause coverage\n",
"% \n",
"% tests ended at 2023-09-26, 12:27:22\n",
"% tests ended at 2023-09-26, 15:45:52\n",
"% "
]
},
Expand Down Expand Up @@ -1022,7 +1030,7 @@
"data": {
"text/plain": [
"Query: list::member(M,[1,2,3])\n",
"Runtime: 0 s"
"Runtime: 0.0 s"
]
},
"metadata": {},
Expand Down Expand Up @@ -1365,6 +1373,8 @@
"\n",
" %help\n",
" Prints documentation for all predicates from object jupyter\n",
" %versions\n",
" Prints Logtalk, Prolog backend, and Jupyter kernel versions\n",
"\n",
" %magic\n",
" Prints help in using cell and line magic"
Expand Down Expand Up @@ -1437,6 +1447,12 @@
"\n",
"--------------------------------------------------------------------------------\n",
"\n",
"jupyter::versions\n",
"\n",
" Prints Logtalk, Prolog backend, and Jupyter kernel versions.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\n",
"jupyter::magic\n",
"\n",
" Outputs the documentation for all cell and line magic.\n",
Expand Down
20 changes: 15 additions & 5 deletions notebooks/LogtalkTutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"\n",
"The default backend can be changed in the fly by adding a code cell at the top and running one of the following queries: `eclipse`, `gnu`, `lvm`, `sicstus`, `trealla`, or `yap`. The default backend can be set for all notebooks in a directory by using a `logtalk_kernel_config.py` file (see the [logtalk-jupyter-kernel](https://github.com/LogtalkDotOrg/logtalk-jupyter-kernel) repo for details). If this file is not present, the default backend is SWI-Prolog.\n",
"\n",
"This Logtalk notebook is currently using the following Prolog backend:"
"This notebook is currently running using:"
]
},
{
Expand All @@ -32,16 +32,26 @@
{
"data": {
"text/plain": [
"\u001b[1mBackend = swi,\n",
"Version = v(9,1,15)"
"Logtalk 3.71.0-b01\n",
"SWI-Prolog 9.1.16\n",
"Logtalk Jupyter kernel 0.7.0-beta"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"\u001b[1mtrue"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"current_logtalk_flag(prolog_dialect, Backend), current_logtalk_flag(prolog_version, Version)."
"%versions"
]
},
{
Expand Down Expand Up @@ -1409,7 +1419,7 @@
{
"data": {
"text/plain": [
"call: list <-- member(_60984,[1,2,3]) from user\n",
"call: list <-- member(_59438,[1,2,3]) from user\n",
"exit: list <-- member(1,[1,2,3]) from user\n",
"exit: list <-- member(2,[1,2,3]) from user\n",
"exit: list <-- member(3,[1,2,3]) from user"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requires = [

[project]
name = "logtalk-jupyter-kernel"
version = "0.6.2"
version = "0.7.0"
authors = [
{ name = "Paulo Moura", email = "pmoura@logtalk.org" },
{ name = "Anne Brecklinghaus" },
Expand Down

0 comments on commit b890fbc

Please sign in to comment.