SWI Prolog pass a goal with non-zero arity through the command line arguments

360 views Asked by At

SWI Prolog allows the execution of a goal before top level with non zero arity as follows

swipl -s consultingfile.pl -g start

however when a predicate with non zero arity is specified as follows

swipl -s consultingfile.pl -g start(1)

It gives an error

syntax error near unexpected token '('

What should be done to pass a non-zero arity predicate as a goal before top level?

1

There are 1 answers

1
willeM_ Van Onsem On BEST ANSWER

I think this has nothing/not much to do with SWI-prolog itself, but more with the command line handler.

If I place the goal between single quotes (''), it works:

swipl -s consultingfile.pl -g 'start(1)'

The brackets are probably wrongly interpreted by the shell.

If I use your command it gives:

$ swipl -s consultingfile.pl -g start(1)
bash: syntax error near unexpected token `('

Mind however the bash before the colon. That means control is never really given to swipl, it is bash that complains about the brackets.

In general it is better to put items into quotes in order to group content as a single parameter.