[英]Parsing from char to digit Prolog
I have the following: 我有以下几点:
is_digit(X):-char_type(X,digit).
When I call it like this: is_digit(X). 当我这样称呼它时:is_digit(X)。
I get the folloring results: 我得到愚弄的结果:
X='0';
X='1';
... ;
X='9'
I need to get those same results but without the quotes. 我需要获得相同的结果,但不带引号。 Excuse me if it is a simple question but I just haven't been able to find a way around this.
打扰一下,如果这是一个简单的问题,但是我只是无法找到解决方法。 Thanks!
谢谢!
?- between(0, 9, X).
X = 0 ;
X = 1 ;
X = 2 ;
X = 3 ;
X = 4 ;
X = 5 ;
X = 6 ;
X = 7 ;
X = 8 ;
X = 9.
If you want to be portable among ISO Prolog implementations, you need to use number_chars/2
. 如果要在ISO Prolog实现中可移植,则需要使用
number_chars/2
。 atom_number/2
exists only in SWI, YAP, Ciao. atom_number/2
仅存在于SWI,YAP,Ciao中。 But number_chars/2
is supported by those 3 and IF, B, GNU, SICStus, XSB, Jekejeke. 但是
number_chars/2
由3和IF,B,GNU,SICStus,XSB和Jekejeke支持。
X = '1', number_chars(N, [X]).
If you want the number use atom_number(A,N). 如果您想要数字,请使用atom_number(A,N)。 ie
即
?- char_type(X,digit),atom_number(X,N).
X = '0',
N = 0 ;
X = '1',
N = 1 ;
X = '2',
N = 2 ;
X = '3',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.