2
votes

Whenever I compile anything with swi-prolog, it adds |: before user input to show that you are supposed to write something, which would be fine, but I need to pipe the output of this program to another program, preferably without the |:.

My compilation options are:

swipl -nodebug -g true -O -q --toplevel=quiet --stand_alone=true -o main -c main.pl
1
are you sure there is no term detection before the |: is printed? try piping it to cat (|cat)to see if that isn't the case.Patrick J. S.
MCVE, please.false
Oh, my bad. You are right, the |: disappear when piping it to cat. Can you explain why this happens though?tolUene
This is the traditional prompt from TOPS-10 operating system. It is still shown when user input is assumed.false

1 Answers

3
votes

You need to say

prompt(_, '')

somewhere in your program before you start reading and writing to standard streams. From the entry for prompt/2:

A prompt is printed if one of the read predicates is called and the cursor is at the left margin. It is also printed whenever a newline is given and the term has not been terminated. Prompts are only printed when the current input stream is user.

The invocation above just sets the prompt to the empty atom (ignoring whatever the prompt was before). For example, with the following prompt.pl:

:- current_prolog_flag(verbose, silent).
:- use_module(library(readutil)).

main :-
    read_line_to_codes(user_input, Line),
    format("~s~n", [Line]),
    halt.
main :- halt(1).

Then:

$ swipl -q --goal=main -o prompt -c prompt.pl
$ ./prompt
|:foobar
foobar
$
:- current_prolog_flag(verbose, silent).
:- use_module(library(readutil)).

main :-
    prompt(_, ''),
    read_line_to_codes(user_input, Line),
    format("~s~n", [Line]),
    halt.
main :- halt(1).

And it is gone:

$ swipl -q --goal=main -o prompt -c prompt.pl
$ ./prompt
foobar
foobar
$

If you have included a program similar to my first version of prompt.pl and the resulting output it might have been easier for more people to understand what exactly you are asking.