What are the basic data types and data structures of Prolog?

I ask this question because I want to use a data structure to represent line segments. My first thought is to use a list. For example, I use [2, 3] to represent a point on a plane coordinate system, and [[2, 3], [7, 3]] to represent a line segment.
But there are also some problems. For a line segment, I don’t care about the front and back positions of its two-point coordinates. But for the list, [[2, 3], [7, 3]] is different from [[7, 3], [2, 3]].
Although predicate permutation can be used to judge whether the contents of two lists are the same, regardless of the order (perhaps there is a better way in this regard?). However, I feel that the code is not elegant, and I doubt it’s operating efficiency.
And if you want to judge a group of data containing more line segment information, this is not easy to use. So I need a data type that can contain multiple data without caring about the order. I think it would be better to represent line segments as a set.
If there is a better way to represent line segments and points, please reply.
Back to the question in the title, what are the basic data types and structures of Prolog? I want to know about this so that I can think of appropriate tools in time when I use prolog to deal with various problems in the future.

A good rule from “The Craft of Prolog” is to “never use a list if the number of elements is fixed”. You should use a compound term instead, typically using a functor that describes
the object. So, line(point(X1,Y1),point(X2,Y2)) would be the obvious choice. If the direction does not matter, make them canonical by ordering the two points. Any ordering relation will do, e.g., Prolog standard order of terms.

You may opt for line(X1,Y1,X2,Y2) as well.

As @anon19431257 says, you could consider a dict, which would result in e.g.

line{from: point{x:X1,y:Y1}, to: point{x:X2,y:Y2}}

But dicts are more interesting if it is common that you only specify part of the properties, there are many properties and there is no natural order or it is likely you want to add more properties later. I think none of these applies here.

3 Likes

the types are in library/error.pl ?

%   types are =atom=, =atomic=, =between=, =boolean=, =callable=,
%   =chars=, =codes=, =text=, =compound=, =constant=, =float=,
%   =integer=, =nonneg=, =positive_integer=, =negative_integer=,
%   =nonvar=, =number=, =oneof=, =list=, =list_or_partial_list=,
%   =symbol=, =var=, =rational=, =encoding=, =dict= and =string=.
%
1 Like