سؤال

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