swi-prolog:在编译程序中的用户输入之前删除“|:" [英] swi-prolog: remove '|:' before user input in compiled program

查看:43
本文介绍了swi-prolog:在编译程序中的用户输入之前删除“|:"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我用 swi-prolog 编译任何东西时,它都会在用户输入之前添加 |: 以表明您应该编写一些东西,这很好,但我需要管道输出程序到另一个程序,最好没有 |:.

我的编译选项是:

swipl -nodebug -g true -O -q --toplevel=quiet --stand_alone=true -o main -c main.pl

解决方案

你要说

prompt(_, '')

在您开始读取和写入标准流之前的程序中的某个位置.来自 prompt/2 的条目:

<块引用>

如果调用读取谓词之一并且光标位于左边距,则会打印提示.每当给出换行符并且术语尚未终止时,也会打印它.提示仅在当前输入流为 user 时打印.

上面的调用只是将提示设置为空原子(忽略之前的任何提示).例如,使用以下 prompt.pl:

:- current_prolog_flag(详细,无声).:- use_module(library(readutil)).主要的 :-read_line_to_codes(user_input, Line),格式(~s~n",[行]),停止.主要:- 停止(1).

那么:

$ swipl -q --goal=main -o prompt -c prompt.pl$ ./提示|:foobar食物吧$

<预>:- current_prolog_flag(详细,无声).:- use_module(library(readutil)).主要的 :-提示(_, ''),read_line_to_codes(user_input, Line),格式(~s~n",[行]),停止.主要:-暂停(1).

它不见了:

$ swipl -q --goal=main -o prompt -c prompt.pl$ ./提示食物吧食物吧$

如果你已经包含了一个类似于我的 prompt.pl 的第一个版本的程序和结果输出,它可能更容易让更多人理解你到底在问什么.

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

解决方案

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.

这篇关于swi-prolog:在编译程序中的用户输入之前删除“|:"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆