Search code examples
prolog

Why in the program "Prolog for eight puzzle" user slago uses the command: reverse([State|States], Path). I can't undestand why he uses this command


What is the meaning of this command in Prolog's commanf line? What does time and what does time(ids)? ?- time(ids)


Solution

  • Prolog lists are singly linked lists and it's more convenient and more performant to prepend things on the front instead of append them on the end. A common technique is to build a list backwards, then reverse it. Slago is doing that.

    The search starts with the Start state in the list, prepends intermediate states, and finishes when goal(State) holds and the state at the front of the list is the solved puzzle.

    Context: https://stackoverflow.com/a/67645940/