Can SWI-Tinker use a library(markup)?

How difficult would it be to bring a library(markup) to SWI-Tinker.
I asked something similar already in the past. In particular
I asked whether the SWI-Prolog streams allow piggy backing

and filtering. The predicate tag/2 would bypass the filtering,
and use the underlying stream of piggy backing. And the predicate
write/1 would use filtering, namely XML escaping. Take this test:

test :-
    tag('<font color="red">'), 
    write('Hello'), 
    tag('</font>'), 
    write(' '), 
    tag('<font color="blue">'), 
    write('World!'),
    tag('</font>'), nl.

Result with SWI-Tinker:

Result with Dogelog Player:

Advantage of such a browser interface:

  • The interface is Hypertext Markup (HTML), which also covers
    Scalable Vector Graphics Markup (SVG), it will not enlarge the
    footprint of your Playground. Its all functionality from the
    browser, you trivially extend the DOM during writing.

  • The interface can be made interactive. With little effort, in
    my case an additional library(react), it is demonstrateable
    to have button clicks etc… handled by pure Prolog callbacks.
    You can even do animation, games, etc.. with pure Prolog.

  • We don’t need lower or higher level MVC, the DOM is the
    model, not a logical one, more a physical one, especially in the
    case of SVG, but you can still use CSS for more flexiblity.

  • Things like my library(plot) from Dogelog Player would work
    in SWI-Thinker. And vice versa if some stuff would arrive on
    SWI-Thinker side, it would also work in Dogelog Player.

  • I have much more like only library(plot). I use a library(vector)
    trivially bootstrapped from library(markup) which provides some
    ways to deal with SVG viewports in a scalable way. You can do
    educational stuff like library(turtle) as in Python:

Turtle Programming in Python
https://www.geeksforgeeks.org/turtle-programming-python/

  • What I didn’t manage to try yet, is measuring the text size,
    and do some more advanced layout, like for example the
    Tau Prolog graphical tracer. What I also didn’t try yet
    is shadow DOM, which would allow to create widgets.

  • I don’t know how the idea relates to PCE, does it have some
    markup language at all? With library(markup) you get a table-
    mode and a plot-mode, all based on XML, which probably
    drives Emacs Cultists completely nuts.

  • The library(markup) also works headless, you can use it to
    generate files such as HTML reports, SVG graphics, etc.. etc..
    This needs a little extra Prolog code in the library and some help
    by the streams to do the HTML layout indentation.

  • Disclaimer: I didn’t look into Trealla, Scryer or Ciao, what they
    support in this respect. I only had a look at SWISH and their
    concept of answer substitutions filters. I find this too restrictive,
    already the library(turtle) cannot be done in this setting.

  • Credits: Mainly go to Tau-Prolog, which had somewhere a HTML
    writer integration. But the present library(markup) is an improvement
    on this HTML writer by the piggy backing design. Unfortunately
    at this moment https://www.tau-prolog.org/ is not savely reachable.

  • What else…?