Simple graph search in Prolog

前端 未结 2 1420
攒了一身酷
攒了一身酷 2021-01-16 03:25

I\'m trying to code a simple graph search in SWI-Prolog. I came up with the following program:

adjacent(1,4). adjacent(4,2). adjacent(3,6).
adjacent(6,4). ad         


        
2条回答
  •  一整个雨季
    2021-01-16 03:48

    The main problem here is the member test: the signature is member(Element,List); you seem to assume that the arguments are the other way 'round.

    In addition, your first path predicate is meant to test a two-element list, however, B really unifies with the rest list (which then isn't connected).

    If you fix these, you find that this can only work for fully instantiated variables, as the negation doesn't work well for unbound variables.

提交回复
热议问题