prolog

Command line argument vectors in Prolog?


Do they exist? I have written a program that solves sudoku puzzles, and it takes 3 steps to run.

> prolog
> consult(sudoku).
> solve(puzzle).

I'm looking for a way to do something like

> prolog puzzle

and be done with it. Is there a way to do this IN Prolog? Or will I have to write some helper program in C or some other language to use like

> ./solve puzzle

Any help would be appreciated. Still new to Prolog, and having trouble finding good documentation.


Solution

  • It depends on the Prolog system your are using. Most Prolog systems have a command line start where one can provide an initial Prolog text to be consulted and an initial Prolog goal to be run.

    Here are some examples, I have combined the consult and run into one conjunctive goal:

    SWI-Prolog:

    > swipl -t ['sudoku.p'],puzzle
    

    GNU Prolog:

    > gprolog --entry-goal ['sudoku.p'],puzzle,halt
    

    Jekejeke Prolog:

    > java -jar interpreter.jar -t ['sudoku.p'],puzzle
    

    Best Regards