Jay Elrod
Jay Elrod

Reputation: 738

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.

Upvotes: 2

Views: 678

Answers (3)

user502187
user502187

Reputation:

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

Upvotes: 2

aurelia
aurelia

Reputation: 677

use optparse

for example, if your program is:

main :-
    opt_arguments([], _, Args),
    write(Args).

and you run it like ./program 1 foo the program will write [1,foo]

Upvotes: 0

Alexander Serebrenik
Alexander Serebrenik

Reputation: 3577

Using the -g flag you can cause Prolog to execute a goal of your choice just before entering the top level. Default is a predicate which prints the welcome message. Moreover, you might like to use the -t flag that would replace the default goal prolog/0 by the one of your choice as an interactive top-level.

See also the manual.

Upvotes: 2

Related Questions