Prolog converting integer to a list of digit
问题 I want to write a predicate that an integer and a list of digits, and succeed if Digits contain the digits of the integer in the proper order, i.e: ?-digit_lists( Num, [1,2,3,4] ). [Num == 1234]. Here is what I have so far: my_digits( 0, [] ). my_digits(N,[A|As]) :- N1 is floor(N/10), A is N mod 10, my_digits(N1, As). 回答1: As already suggested, consider using finite domain constraints: :- use_module(library(clpfd)). number_digits(Number, 0, [Number]) :- Number in 0..9. number_digits(Number, N