0

I am looking for something like this:

g(X, ...Y) :- f(X, ...Y) .

which will be a syntactic sugar for:

g(X, Y) :- f(X, Y) .
g(X, Y, Z) :- f(X, Y, Z) .
g(X, Y, Z, Z1) :- f(X, Y, Z, Z1) .
%...and so on

is there any way to provide some such syntactic sugar, just I have to type less?

Sid Datta
  • 1,110
  • 2
  • 13
  • 29
  • Similar question at https://stackoverflow.com/questions/61746114/is-there-a-method-to-represent-arbitrary-length-tuple-in-clingo – Sid Datta Aug 19 '21 at 20:00

1 Answers1

1

No, there is no such thing for arguments of predicates. But you could use functions instead.

f((1)).
f((1,2)).
f((1,2,3)).
f((1,2,3,4)).
g(X) :- f(X).

The key here is that f has only one parameter which is a tuple. And X refers to the whole tuple. You can then still access single elements of specific tuples using h(X) :- g((,,X)).

Remarks: I think in general it is a problem with your datastructures that you have f/n with an unknown number of arguments. You can not write rules about these facts as you do not know the meaning or number of arguments. If you want to store e.g. a list of [a,b,c,d,e], use something like:

f(id1,a).
f(id1,b).
f(id1,c).
f(id1,d).
f(id1,e).

These facts can then be used with the : operator to generate sets etc...

Max Ostrowski
  • 575
  • 1
  • 3
  • 15
  • Thanks! Using tuples is a good idea. Though it looks like writing complex clingo programs by hand is a chore, I will use python or something to convert my own complex representation to something like your option 2, which is easier to reason about. – Sid Datta Aug 19 '21 at 20:03
  • The creation of the facts should be automated, no doubt. The creation of the rules should never be automated and always be done by hand. This is a common pitfall. If you require something else you are doing something wrong (just a rule of thumb) – Max Ostrowski Aug 23 '21 at 05:54