문제

I have the following:

is_digit(X):-char_type(X,digit).

When I call it like this: 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!

도움이 되었습니까?

해결책

If you want the number use atom_number(A,N). i.e.

?- char_type(X,digit),atom_number(X,N).
X = '0',
N = 0 ;
X = '1',
N = 1 ;
X = '2',
N = 2 ;
X = '3',

다른 팁

?- 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. atom_number/2 exists only in SWI, YAP, Ciao. But number_chars/2 is supported by those 3 and IF, B, GNU, SICStus, XSB, Jekejeke.

X = '1', number_chars(N, [X]).
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top