-1

I have some problem whith this code. The func3 was never invoked :

technology(board, saw, table).
technology(wood, sanded, board).
technology(water, grow, tree).

material(table, board, 20).
material(table, tree, 5).
material(wood, water, 100).

equipment(table,saw, cut, 10).
equipment(board, plane, polish, 7).
equipment(tree, watering, growing, 100).

specialization(saw, wood).
specialization(plane, wood).
specialization(watering, forestry).

plan_vypusku(table,10).

potreba_u_zahotovkah1(M, V):-
    write(M + V),
    nl,
    technology(F, _, M),
    material(M, F, C),
    Z is V * C,
    write(F - Z),
    nl.

func3([A, B], C):-
    write("InF3"),
    nl,
    potreba_u_zahotovkah1(A, C),
    func3(B, C).

func2([A, B], C):-
    write("InF2"),
    nl,
    findall(M, equipment(M, A, _, _), ML),
    write(ML),
    nl,
    func3(ML, C),
    func2(B, C).

potreba_u_zahotovkah(C, G):-
    findall(X, specialization(X, C), XL),
    write(XL),
    nl,
    plan_vypusku(G, S),
    func2(XL, S).

Result:

?- potreba_u_zahotovkah(wood,table).
[saw,plane]
InF2
[table]
false.

Help PLS!

false
  • 10,264
  • 13
  • 101
  • 209
  • 3
    See [this](http://stackoverflow.com/a/30791637/772868) for a more systematic way to debug your program. – false Dec 27 '15 at 20:13

1 Answers1

0

I don't know what you're up to, but I have an explanation of the unexpected failure you observed.

The query you made wrote the following lines by side-effect (write/1 and nl/0) and then failed:

?- potreba_u_zahotovkah(wood,table).
[saw,plane]
InF2
[table]
false.

The highlighted line was output by the following highlighted write/1 and nl/0:

func2([A, B], C):-
    write("InF2"),
    nl,
    findall(M, equipment(M, A, _, _), ML),
    write(ML),
    nl,
    func3(ML, C),
    func2(B, C).

So above variable ML was bound to [table] when the goal func3(ML, C) was called.

Looking at your definition of func3/2 the reason for failure becomes apparent:

func3([A, B], C):-
    write("InF3"),
    nl,
    potreba_u_zahotovkah1(A, C),
    func3(B, C).

The clause head of func3/2 demands that the first argument is a list having exactly two elements. The list [table], however, has exactly one element, not two!

As no more choicepoint are open, the goal potreba_u_zahotovkah(wood,table) fails.

repeat
  • 18,496
  • 4
  • 54
  • 166