Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A Standard for Prolog Notebooks?

134 views
Skip to first unread message

burs...@gmail.com

unread,
Feb 24, 2018, 9:45:42 PM2/24/18
to
Is there already a standard for Prolog notebooks?
Here is my own very minimal take on it:

- The idea is that notebooks are executed locally, inside
the Prolog system, so that we don't need much of a sandbox.
They are Prolog modules and the trust needed to execute
them, is the same as for any other Prolog module. So
sandbox is rather optional.

- As a Prolog module they will be easily understood
by any end-user. Notebooks are Prolog modules that
have a secondary purpose than only being consulted. The
secondary purpose is that they are to contain queries which
are automatically displayed to the end-user and which can
be modified by the end-user.

- Without specifying how the displaying or the modification
is performed we provide directives to embed queries inside
Prolog modules. The idea is that normal ISO comments are
the text cells of a notebook, that normal ISO clauses/
directives are the program cells of a notbook and that a
new directive marks queries. The new directive is:

?- <Goal>
The directive succeeds always. Whenever the goal G
succeeds, the directive will show the solution. When the
goal G fails, the directive will show a no.

Can this idea really be used? I dunno yet. I don't see
a lot of places for new markup, respectively this is
rather optional. The ISO comments, with /* */, are simply
stripped, and what is there can be shown. Following the
lines of Java javadoc, its possible to directly have HTML
in the comments.

Most Prolog systems should be able to implement the ?- directive,
since most Prolog systems have a top-level. I made it available
via a new library(notebook/directives). Here is an example
notebook, which enhances the capability of the top-level
query predicate by using a module library(advanced/sequence)
and the predicate limit/2 and offset/2 from there.

Example Notebook Text: answer.p

:- use_module(library(notebook/directives)).
:- use_module(library(advanced/sequence)).

p(1).
p(2).
p(3).

?- p(4).

?- p(2).

?- p(X).

?- limit(1, offset(1, p(X))).

Example Notebook Execution:

Jekejeke Prolog 2, Development Environment 1.2.7
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- set_prolog_flag(verbose, off).
Yes

?- ensure_loaded('answer.p').
No

Yes

X = 1 ;
X = 2 ;
X = 3

X = 2

In the above I have used set_proloh_flag(verbose, off), to
suppress messages from the ensure_loaded/1 invocation. What
I wanted to see whether I can generate answer packages. The
answer packages resemble what the top-level gives, we also
detect determinism and suppress unnecessary no messages.

From here it shouldn't be so difficult to develop either static
or dynamic notebooks. The answer stream needs to be meshed with
the formatting of the text and code cells. Possibly it should
be also allowed to edit cells. What needs a little bit more
smarts is to avoid unnecessary recalculation.

For unncessary recalculation I guess there are different strategies
around. A dumb approach would be to effectively do a reconsult,
something between consult/1 and ensure_loaded/1 to avoid
reconsulting modules. And then repopulate the answers and/or
use modified queries. If a Browser is involved, a lean version

could even do without any JavaScript.

burs...@gmail.com

unread,
Feb 24, 2018, 10:01:17 PM2/24/18
to
Concerning these answer packages. The top-level
is a little bit deceiving. For example it shows:

?- X = f(Y).
X = f(Y)

But internally we cannot pass around X=f(Y), since
X is instantiated. So we would either pass around
'X' = f(Y), or already do some serialization when
delivering an element from an answer package. Need

to investigate what is the best solution and what
are the requirements. Lets see. The modules
library(notebook/directives) and library(advanced/sequence)
are open source already. Screenshots of the

raw prototype are also given here:

Preview: New module notebook/directives. (Jekejeke)
https://plus.google.com/+JekejekeCh/posts/jVxLGbJZMEj

burs...@gmail.com

unread,
Feb 25, 2018, 8:56:45 PM2/25/18
to
We found a way to do the mesh up with a very
simple approach. Basically we use the term
expansion again, but this time to simply write
out the cells without the query result. Together
with the expansion that does the query evaluation,
we get the desired result of an evaluated notebook.

Preview: Learn Prolog Now as a Notebook. (Jekejeke)
https://plus.google.com/+JekejekeCh/posts/1WUfpxkFA9f

n2kr...@gmail.com

unread,
Feb 28, 2018, 11:12:15 AM2/28/18
to
Attempt to self host on SWI PceEmacs / XPCE ?

Or it does also have an web server.
Would that make a prolog -> JavaScript useful ?

burs...@gmail.com

unread,
Feb 28, 2018, 12:05:45 PM2/28/18
to
Hi,

SWISH Notebooks are very complicated, I am seeking
a much simpler format. For example if I use the
download function of SWISH,

I get some XML garbel, that I cannot edit and test
run in a normal Prolog IDE. It should be possible to
have Notebooks as normal Prolog texts inside

a Prolog project. I don't want to turn node.js
developer when I am creating Notebooks. I want to
stay Prolog developer that can focus on the

Prolog problem at hand, and note turn web expert.
You can check yourself:

https://github.com/SWI-Prolog/swish/blob/master/examples/tabling.swinb

It has:

a) HTML around Prolog, and not inside Prolog comments,
so the Prolog text itself needs to be escaped,
a legal Prolog text like below would confuse
the Notebook:

p('</div>').

b) Some custom vendor mark-down in it, I would
prefer some portable HTML mark-up inside ISO comments.
To avoid mark-down processor dependency. Mark-down
could be a feature of some editor/tool to suite the
end-user, but as a format?(*) Nay.


If the query cells were just (?-)/1 directives:

You could:

a) Consult these files by any Prolog interpreter,
just see to it that the (?-)/1 operator is defined.
In the worst case you will get a couple of facts
for (?-)/1, and side effects of queries will
not be processed.

b) Be able to use the ISO read_term/write_term to
process such files. Prolog text files have many
use cases besides consulting. In an IDE you want
to beautify, critique, refactor, etc.. them.

c) I want to use Eclipse, IntelliJ, Visual Studio Code
etc.. with the any Prolog plug-in to edit and debug
notebooks. I want to jump into source lines of
a notebook during debugging.

Have a Nice day!

(*)
How difficult is it to make mark-down disappear in the
persisting of a text? You should be able to regenerate
mark-down if needed from HTML.

Also use a varying number of mark-down processors all
generating HTML, could then be supported. You only
need the back path offered by the processor as well.

burs...@gmail.com

unread,
Feb 28, 2018, 12:11:09 PM2/28/18
to
Summary:
- My view of a Notebook:
Prolog rules/facts with text/queries.

- Another view of a Notebook:
Text with Prolog rules/facts/queries.

burs...@gmail.com

unread,
Feb 28, 2018, 12:16:21 PM2/28/18
to
The text view could be ultimately appropriate,
if you mix different languages. Maybe this
is the reason.

But lets say if you aim at **Prolog** notebooks,
then well you can view it the other way around.
Prolog first(*), Text next.

(*)
Loosely after Donald Trump

burs...@gmail.com

unread,
Mar 2, 2018, 11:43:09 AM3/2/18
to
Actually I am not principally opposing other formats.
I guess a lot of formats could be invented. Using
Prolog texts itself is one option.

Another option, compared to the SWISH approach, is
the JavaScript Prolog interpreter approach. Here
there is neither HTML nor mark-down,

but only JavaScript, at least currently. Example:

"What is Tau Prolog?
Tau Prolog is a Prolog interpreter fully implemented
in JavaScript. While most online interpreters are remote
servers with an installed version of the interpreter which
receive code, execute it and return the results, Tau
Prolog is fully implemented on JavaScript and the code
is analysed and parsed on the client side."
http://tau-prolog.org/

I think bringing the code to the client has a lot
of advantages. The provider needs to pay less fees
for the cloud, and the end-user can use Prolog

even in Greenland, provided he downloads everything
before hiding in some of the mountains...

burs...@gmail.com

unread,
Mar 21, 2018, 9:06:20 AM3/21/18
to
Tau Prolog seems to be more suitable
for teaching than the default settings
of SWI-Prolog. At least what concerns

the many text books that use old style
lists. Here is what I get. SWI7 made a
change you get:

?- functor([a|b],A,_), atom(A).
A = '[|]'.
?- functor([],A,_), atom(A).
false.

But the old ISO style was, also
implemented by the tau sandbox:
http://tau-prolog.org/sandbox/

?- functor([],A,_), atom(A).
A = [] ;
?- functor([a|b],A,_), atom(A).
A = '.' ;

burs...@gmail.com

unread,
Apr 2, 2018, 8:59:17 PM4/2/18
to
Yet another newcomer:

X-Prolog for Android: no [user], no big nums but with editor!
https://play.google.com/store/apps/details?id=org.xprolog.xp
0 new messages