ENHANCED: more memory efficient call_nth/2 (#1264)
I hope that this will allow more extensive tests of Scryer Prolog. Enjoy!
This commit is contained in:
@@ -210,28 +210,33 @@ call_nth(Goal, N) :-
|
|||||||
)
|
)
|
||||||
; true
|
; true
|
||||||
),
|
),
|
||||||
setup_call_cleanup(call_nth_nesting(ID),
|
setup_call_cleanup(call_nth_nesting(C, ID),
|
||||||
( Goal,
|
( Goal,
|
||||||
retract(i_call_nth_nesting(ID,N0)),
|
bb_get(ID, N0),
|
||||||
N1 is N0 + 1,
|
N1 is N0 + 1,
|
||||||
asserta(i_call_nth_nesting(ID,N1)),
|
bb_put(ID, N1),
|
||||||
( integer(N) ->
|
( integer(N) ->
|
||||||
N = N1,
|
N = N1,
|
||||||
!
|
!
|
||||||
; N = N1
|
; N = N1
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
( retract(i_call_nth_nesting(ID,_)),
|
( bb_get(i_call_nth_counter, C) ->
|
||||||
retract(i_call_nth_counter(ID))
|
C1 is C - 1,
|
||||||
|
bb_put(i_call_nth_counter, C1)
|
||||||
|
; true
|
||||||
)).
|
)).
|
||||||
|
|
||||||
call_nth_nesting(ID) :-
|
call_nth_nesting(C, ID) :-
|
||||||
( i_call_nth_counter(ID0) ->
|
( bb_get(i_call_nth_counter, C0) ->
|
||||||
ID is ID0 + 1
|
C is C0 + 1
|
||||||
; ID = 0
|
; C = 0
|
||||||
),
|
),
|
||||||
asserta(i_call_nth_nesting(ID, 0)),
|
number_chars(C, Cs),
|
||||||
asserta(i_call_nth_counter(ID)).
|
atom_chars(Atom, Cs),
|
||||||
|
atom_concat(i_call_nth_nesting_, Atom, ID),
|
||||||
|
bb_put(ID, 0),
|
||||||
|
bb_put(i_call_nth_counter, C).
|
||||||
|
|
||||||
|
|
||||||
copy_term_nat(Source, Dest) :-
|
copy_term_nat(Source, Dest) :-
|
||||||
|
|||||||
Reference in New Issue
Block a user