0

For example, I input four node:

node(a). node(b). node(c). node(d).

Without no hard-code, how can I pick an arbitrary input as a variable.

I set a root(A)

I want root(A) equal to node(a)

2 Answers2

0

You can add the clause root(A):- node(A)., then you will also get root(a), ..., root(d) in the answer set.

damianodamiano
  • 2,528
  • 2
  • 13
  • 21
0

Something like root(X) :- X=#min{V : node(V)}.

should do the trick. This takes the lexicographically smallest one (which is kind of arbitrary ;) ).

Max Ostrowski
  • 575
  • 1
  • 3
  • 15