interpl

Experiments with intepreters in Prolog
git clone https://ccx.te2000.cz/git/interpl
Log | Files | Refs | README

edcg_example.pl (454B)


      1 :- use_module(edcg).
      2 
      3 % Declare accumulators
      4 edcg:acc_info(adder, X, In, Out, plus(X,In,Out)).
      5 
      6 % Declare predicates using these hidden arguments
      7 edcg:pred_info(len,0,[adder,dcg]).
      8 edcg:pred_info(increment,0,[adder]).
      9 
     10 increment -->>
     11     [1]:adder.  % add one to the accumulator
     12 
     13 
     14 len(Xs,N) :-
     15     len(0,N,Xs,[]).
     16 
     17 len -->>
     18     [_],  % 'dcg' accumulator has an element
     19     !,
     20     increment,  % increment the 'adder' accumulator
     21     len.
     22 len -->>
     23     [].