SWI-Prolog/swish

Cells as facts

Risto-Stevcev opened this issue · 1 comments

I don't know if this is already available or if there's already a way to do this, but I think it would be cool to be able to label cells so they can be used as facts. For example,

Markdown and HTML cells could be labelled. Which would be equivalent to something like:

my_markdown_cell_label("This is some `markdown` content that's in the cell")
my_html_cell_label("<span>This is some html</span>")

The idea being that you can then reference the Notebook in another Program or Notebook file, and then build a rich interaction with the text!

I'm a prolog noobie, but I'm thinking you could do some interesting stuff with this sort of thing. Like for example, you could label ideas and find ideas that have similar phrases in them:

?- assert(contains(A, B) :- sub_string(A, _, _, _, B)).
true.

?- assert(my_idea("A description of my idea. It does this thing, and that thing.")).
true.

?- assert(my_other_idea("A description of my other idea. It does this thing, and some other thing.")).
true.

?- my_idea(X), contains(X, "this thing"); my_other_idea(X), contains(X, "this thing").
X = "A description of my idea. It does this thing, and that thing." ;
X = "A description of my other idea. It does this thing, and some other thing." ;
false.

In the above example, you could use the facts my_idea and my_other_idea in another Program or Notebook and describe something interesting.

It might even be useful to extend the markdown syntax to include a way to tag a phrase inside the markdown as a fact as well:

```
This is a description of my_fact(some thing)
```

Which would maybe render as emphasized (or no formatting):

"This is a description of some thing"

But it would be available as a fact, equivalent to:

my_fact("some thing").

% Text without spaces could be atoms
my_fact(something).

Labels on query cells could be converted into clauses:

Query cell contents with a label "released_since_this_century":

released_since(M, 2000), M0)

Becomes:

released_since_this_century(M) :- released_since(M, 2006), M0).

And program cells with labels could be useful,

Is there some kind of way to get the program body? I'm thinking something like module and clause but for program cells:

:- module(foo, [bar/1, baz/2])).
:- module(foo, Body).
Body = [bar/1, baz/2].
:- clause(format(X), Body).
Body = format(X, []).

There are definitely lots of possibilities or interlinking notebooks. As is, you can only reuse programs and create hyperlinks from notebooks to programs and other notebooks. I see a lot of enthusiastic ideas. The SWI-Prolog forum is probably a better place to discuss this. You can of course also try to make SWISH do what you want it to do. I'm happy to point at the code.