There are several ways to do it. One straight-forward way is as follows:
We can represent comments by facts like:
comment_id_user_text_points(3, 1, 'hello!', []).
I do not know what exactly you mean by "points", so I have simply supplied an empty list (fourth argument) in this case. Note that there is an ID for the comment, and an ID for the user that posted the comment. Therefore, we say that this is a
relation between users and comments and their text and points, usable in all directions.
Each user can likewise be represented as follows, relating a unique ID to a name and e-mail address:
user_id_name_email(1, 'randomUser1122', [random,'ycombinator.com']).
For
admins, I can simply add additional facts, relating user IDs to
rights like this:
admin_id_rights(1, [delete,hide]).
Now, we can simply post
queries over these facts, such as:
?- user_id_name_email(ID, _, _),
comment_id_user_text_points(_, ID, Text, _).
and obtain, on backtracking, all comments for any user.
This is all completely analogous to how you would represent such data in any database system. It's more convenient in Prolog though for several reasons.
We can represent comments by facts like:
I do not know what exactly you mean by "points", so I have simply supplied an empty list (fourth argument) in this case. Note that there is an ID for the comment, and an ID for the user that posted the comment. Therefore, we say that this is a relation between users and comments and their text and points, usable in all directions.Each user can likewise be represented as follows, relating a unique ID to a name and e-mail address:
For admins, I can simply add additional facts, relating user IDs to rights like this: Now, we can simply post queries over these facts, such as: and obtain, on backtracking, all comments for any user.This is all completely analogous to how you would represent such data in any database system. It's more convenient in Prolog though for several reasons.