This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/library/dbqueues.yap
vsc beba8315ca fix nasty overflows in and add some very preliminary support for very large
clauses with lots
of disjuncts (eg, query packs).


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1676 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2006-07-27 19:04:56 +00:00

49 lines
1.1 KiB
Prolog

% A library to implement queues of DB Terms
:- module(dbqueue, [
db_enqueue/2,
db_dequeue/2,
db_clean_queue/1
]).
:- unhide('$init_db_queue').
:- unhide('$db_enqueue').
:- unhide('$db_dequeue').
db_enqueue(Name,El) :- var(Name),
throw(error(instantiation_error(Name),db_enqueue(Name,El))).
db_enqueue(Name,El) :- \+ atom(Name), !,
throw(error(type_error_atom(Name),db_enqueue(Name,El))).
db_enqueue(Name,El) :-
recorded('$db_queue',[Name|Ref],_), !,
prolog:'$db_enqueue'(Ref, El).
db_enqueue(Name,El) :-
prolog:'$init_db_queue'(Ref),
recorda('$db_queue',[Name|Ref],_),
prolog:'$db_enqueue'(Ref,El).
db_dequeue(Name,El) :- var(Name),
throw(error(instantiation_error(Name),db_dequeue(Name,El))).
db_dequeue(Name,El) :- \+ atom(Name), !,
throw(error(type_error_atom(Name),db_dequeue(Name,El))).
db_dequeue(Name,El) :-
recorded('$db_queue',[Name|Ref],R),
( prolog:'$db_dequeue'(Ref, El) ->
true
;
erase(R),
fail
).
db_clean_queue(Name) :-
recorded('$db_queue',[Name|Ref],R), !,
erase(R),
db_dequeue_all(Ref).
db_clean_queue(_).
db_dequeue_all(Ref) :-
( prolog:'$db_dequeue'(Ref, _) -> db_dequeue_all(Ref) ; true ).