Search code examples
recursionprologdatalog

When working with Datalog Educational System (DES), is it possible to create a similar effect to the exclamation mark in Prolog?


I am working with the Datalog Educational System (DES) and I want to create an example deductive database, that recursively derives the overall value of assemblies which can also have sub-assemblies, as well as routine parts. It would work really rather well, if not for the fact that I cannot stop both the recursive and non-recursive clause from being executed. Here are the clauses that are creating the problem:

kop_as(A,B,C) :-
  assembly(A,C),
  sum(rek_as(A,D),D,B).

rek_as(A,B) :-
  a_s(A,C,Y),
  viena_as(A,D,_),
  rek_as(C,E),
  B=(D+E)*Y.

rek_as(A,B) :-
  viena_as(A,B,_).

In this case the output is quite essentially doubled, as both the first rek_as and second rek_as clause gets executed. Basically I would like to do something like this:

kop_as(A,B,C) :-
  assembly(A,C),
  sum(rek_as(A,D),D,B).

rek_as(A,B) :-
  a_s(A,C,Y),
  viena_as(A,D,_),
  rek_as(C,E),
  B=(D+E)*Y,!.

rek_as(A,B) :-
  viena_as(A,B,_).

But that just gives me a compilation mistake about using wrong syntax.


Solution

  • Never mind, I found a solution minutes afterwards. The solution was not to do calculations in the recursive clause at all and leave all the number crunching to the non-recursive clause.