[英]Reading numbers from stdio in B-Prolog
What's the easiest way to read a number or several space-separated numbers (NOT followed by a period) in B-Prolog from standard input? 从标准输入中读取B-Prolog中的一个或多个以空格分隔的数字(不带句号)的最简单方法是什么?
For example, for ECliPse I wrote these simple predicates (I don't need error handling): 例如,对于ECliPse,我编写了这些简单的谓词(我不需要错误处理):
read_number(N) :-
read_token(Token, _),
(
Token == -
->
read_token(Nabs, _),
N is -1 * Nabs
;
N is Token
).
read_numbers_list(Ns) :-
read_string(end_of_line, _, String),
split_string(String, " ", "", Ss),
( foreach(S, Ss), foreach(N, Ns) do
number_string(N, S) ).
But writing something like this for B-Prolog looks overly complicated to me - there are no read_token, or split_string... 但是为B-Prolog编写这样的内容对我来说太复杂了-没有read_token或split_string ...
It there an easy way for such a mundane task? 这样简单的任务有简单的方法吗? Maybe some standard predicate I somehow overlooked?
也许我以某种方式忽略了一些标准谓词?
I ended up with just preprocessing input outside of Prolog and then using read/1
. 最后,我只对Prolog之外的输入进行了预处理,然后使用
read/1
。
Also, info from B-Prolog creator Neng-Fa Zhou ( https://groups.google.com/forum/?fromgroups#!topic/comp.lang.prolog/KSXc2QTWZck ): 另外,来自B-Prolog创作者Neng-Fa Zhou( https://groups.google.com/forum/?fromgroups#!topic/comp.lang.prolog/KSXc2QTWZck )的信息:
You can use an internal predicate, called read_next_token(Type,Val), for your purpose.
您可以使用内部谓词read_next_token(Type,Val)来达到目的。 Another predicate, called b_NEXT_TOKEN_ff(Type,Val), does the same thing but is faster.
另一个谓词b_NEXT_TOKEN_ff(Type,Val)执行相同的操作,但速度更快。 These predicates are not documented.
这些谓词没有记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.