I have a small grammar that turns a number sequence, say 1,2,3,4,9
into a range/integer list: 1-4,9
Here is the code:
% :- table intrange_list(min,_,_). % Send bug report?
:- table intrange_list//1.
% Consolidate N, followed by (N+1)-H
intrange_list([L-H]) -->
integer(L),
`,`,
{ L #= L1 - 1 },
intrange_list([L1-H]).
% Basic N,N+1 sequence
intrange_list([L-H]) -->
integer(L),
`,`,
integer(H),
{ H #= L + 1 }.
% Sequence followed by sequence or integer.
intrange_list([L-H|Ls]) -->
intrange_list([L-H]),
`,`,
intrange_list(Ls).
% Integer followed by sequence or integer or by itself.
intrange_list([i(N)|Ls]) -->
integer(N),
( `,`, ! | [] ),
intrange_list(Ls).
% End of list.
intrange_list([]) --> [].
Producing the following output:
2 ?- phrase(intrange_list(L),`1,2,3,4,9`).
L = [i(1), i(2), i(3), i(4), i(9)] ;
L = [i(1), i(2), 3-4, i(9)] ;
L = [i(1), 2-3, i(4), i(9)] ;
L = [i(1), 2-4, i(9)] ;
L = [1-3, i(4), i(9)] ;
L = [1-2, i(3), i(4), i(9)] ;
L = [1-2, 3-4, i(9)] ;
L = [1-4, i(9)].
I want to keep only the shortest answer (taking advantage of term ordering), so instead of using regular tabling I switched to:
:- table intrange_list(min,_,_).
But now I get this error:
5 ?- phrase(intrange_list(L),`1,2,3,4,9`).
ERROR: Uninstantiated argument expected, found [2-_16240]
ERROR: In:
ERROR: [21] throw(error(uninstantiation_error(...),_16290))
...
Answer subsumption is not accepting the partially uninitialized term [2-_]
, why not allow partially uninstantiated terms?
Perhaps I am missing something.