Predicate: group_by/4

data(a,1).
data(b,2).
data(b,3).
data(a,4).
?- group_by(A, B, data(A,B), Bag).
A = a,
Bag = [1, 4] ;
A = b,
Bag = [2, 3].

The data as a separate predicate as before is probably good as it pollutes the example less.

data(a,1).
data(b,2).
data(b,3).
data(a,4).
?- group_by(A, B, data(A,B), Bag).
A = a,
Bag = [1, 4] ;
A = b,
Bag = [2, 3].

@jan

Do you want it so that anyone can respond in the category Example?

My understanding was that the category Example topics should have only one post with the example and that all discussion would take place in the category Example Discussion. I can set up the category Example Discussion to flag all replies for moderator attention which can then be routed (manually) to the category Example Discussion.

If not I will just move the replies in category Example Discussion into the corresponding Examples and delete the Example Discussion category.

The reason I prefer having a separate category for discussions is that it allows multiple independent threads to exist as they can be created as new topics.

If all of the responses are in one topic, i.e. the category Example, then people will have to mentally untangle the threads. In other words Discourse does not allow for branches in topics like here in Lambda-the-Ultimate; Discourse only allows for a single list for a topic.

I propose to wait a little and see how people willing to contribute examples want to handle this. For now the working link is the GitHub repo which is connected through a webhook to update https://eu.swi-prolog.org. https://us.swi-prolog.org currently pulls every 5 mn and the CDN content times out in one hour.

So, we can submit stuff to github and enjoy it immediately on https://eu.swi-prolog.org.

1 Like

Back to the example instead of talking about the meta of examples.

While I do agree that this is a much simpler example, for a new user who would want to just cut and paste the example to understand it, when they go to cut and paste in the data that should be in the Prolog database they will be confronted with

?- data(a,1).
data(b,2).
data(b,3).
data(a,4).ERROR: Unknown procedure: data/2 (DWIM could not correct goal)
?- ERROR: Unknown procedure: data/2 (DWIM could not correct goal)
?- ERROR: Unknown procedure: data/2 (DWIM could not correct goal)
?- 

To avoid the error was the reason I put the data into a list, but I do know that that is not the normal way to use the predicate.

Eariler version of example which has now been revised.

?- List=[(a,1), (b,2), (b,3), (a,4)],group_by(A,B, member((A,B),List), Bag).
List = [(a, 1),  (b, 2),  (b, 3),  (a, 4)],
A = a,
Bag = [1, 4] ;
List = [(a, 1),  (b, 2),  (b, 3),  (a, 4)],
A = b,
Bag = [2, 3].

So far examples needing data in the Prolog database, what should be done?

Should we note that examples are aimed at a user with a level of understanding that a person who has completed a single semester of a university course would have, should we aim for a level that they have at least completed the exercises from Learn Prolog Now!, should examples using the Prolog database include a link on how to get the data into the Prolog database?

I know, let’s wait and see. :slightly_smiling_face:

I am starting to think I need to start collecting these questions into a separate post so that as was we address them we can cross them off the list.

I think, find a way to make that work. Some things that might make sense are

  • Embed SWISH as LPN. Would work great for this example. Would not work for things that need more context and in particular not for things that need stuff you cannot do within the sandbox restrictions.
  • Somehow allow download or copy/paste the data in such a way that it is easy to get into the database. In theory we can copy/paste the code with [user]. in front and end_of_file behind, but this type of behavior might raise some questions as in how far we understand security :frowning:
  • Just have a general help link from examples on how to use them.
1 Like

Yes. The Prolog source vs. interactive top level is a problem for absolute beginners. I don’t know for how long anyone stays in that place. I would expect that a person is confused about this exactly once in their life. There might be bias is one is fresh from answering homework questions, as those seem to provide an infinite supply of absolute beginners.

1 Like

I agree. Not every page of the manual can assume the user is a beginner. That makes the descriptions needlessly verbose and makes it less efficient for the more experienced users who are after all the main target users of SWI-Prolog. Small examples also help the more experienced users though.

Embedding SWISH should do for most simple predicates and thus nicely supports beginners while it may even have some value for experienced users.