DCG grammars failure

I’m using: SWI-Prolog version SWI-Prolog version 8.4.2 for x86_64-linux

I want the code to work as provided in manual SWI-Prolog -- Manual

But what I’m getting is this error

:- string_to_list("42",L), write_ln(L), phrase(integerL(L),Res,[]).                                                                              
[52,50]
ERROR: Stack limit (1.0Gb) exceeded
ERROR:   Stack sizes: local: 2Kb, global: 0.8Gb, trail: 0Kb                                                                                      
ERROR:   Stack depth: 14,383,078, last-call: 100%, Choice points: 5                                                                              
ERROR:   In:                                                                                                                                     
ERROR:     [14,383,078] user:digits([length:1|_201363078], _201363070, _201363072)                                                               
ERROR:     [13] user:integerL([length:2], '<garbage_collected>', [])                                                                             
ERROR:     [12] '$dcg':call_dcg('<garbage_collected>', '<garbage_collected>', [])                                                                
ERROR:     [9] '$toplevel':toplevel_call('<garbage_collected>')                                                                                  
ERROR:     [8] '$toplevel':stop_backtrace('<garbage_collected>')                                                                                 
ERROR:                                                                                                                                           
ERROR: Use the --stack_limit=size[KMG] command line option or                                                                                    
ERROR: ?- set_prolog_flag(stack_limit, 2_147_483_648). to double the limit.

My code looks like this:

integerL(I) -->
        digit(D0),
        digits(D),
        { number_codes(I, [D0|D]) }.

digits([D|T]) -->
        digit(D), !,
        digits(T).
digits([]) -->
        [].

digit(D) -->
        [D],
        { code_type(D, digit) }.

You swapped the input and the output. Should be phrase(integerL(Res),L,[])

Of course! :frowning: I’m sorry! Thanks a lot!