swi-prolog: remove '|:' before user input in compiled program

吃可爱长大的小学妹 提交于 2019-12-12 22:17:39

问题


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:


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.



来源:https://stackoverflow.com/questions/30561323/swi-prolog-remove-before-user-input-in-compiled-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!