Article View: comp.lang.prolog
Article #4186Re: Public Domain Prolog Interpreters
From: Richard O'keefe
Date: Tue, 13 Feb 1990 08:13
Date: Tue, 13 Feb 1990 08:13
73 lines
3068 bytes
3068 bytes
In article <1871@naucse.UUCP>, kwc@naucse.UUCP (Ken Collier) writes:
> I need a Prolog interpreter that supports the following utilities:
> recorda/3
> recordz/3
> erase/1
> recorded/3
> We are currently using version 3.0 of the SB Prolog interpreter from
> Sunny Brook New York, running on a MicroVAX on top of Berkeley UNIX.
Given that the SB in SB Prolog stands for Stony Brook and that
SB Prolog is a compiler, are you _sure_ you're using SB Prolog?
I just FTPd a copy of the 3.1 SB Prolog manual, and each of these
commands is described in that manual.
The commands recorda/3, recordz/3, recorded/3, and erase/1 can be
simulated quite easily. Recall the interface:
recorda(+Key, +Term, -Ref)
recordz(+Key, +Term, -Ref)
recorded(+Key, ?Term, ?Ref)
or recorded(?Key, ?Term, +Ref)
erase(+Ref)
In this interface, the significant part of Key is the FUNCTOR,
that is the *pair* FunctionSymbol/Arity; Term is any term, even a
variable, and all that is guaranteed about Refs is that
they are ground terms uniquely labelling (records in the recorded
data base or clauses in the clause store). Data base references
are not an "efficiency" hack but a SEMANTIC hack; they are unique
names.
So, let's maintain two tables. The first table will be a table
of counters and the second will be a table of the actual records.
We'll represent a data base reference by a triple '$REF'(F,N,I)
meaning the Ith tuple to be stored under the key F/N.
:- dynamic
ref_counter/2,
recorded/3.
recorda(Key, Term, Ref) :-
ref_counter(Key, Tag, Ref),
asserta(recorded(Tag,Term,Ref)).
recordz(Key, Term, Ref) :-
ref_counter(Key, Tag, Ref),
assertz(recorded(Tag,Term,Ref)).
erase(Ref) :-
retractall(recorded(_,_,Ref)).
ref_counter(Key, Tag, '$REF'(F,N,I)) :-
functor(Key, F, N),
functor(Tag, F, N),
( ref_counter(Tag, I0) ->
I is I0+1,
asserta(ref_counter(Tag,I)),
retractall(ref_counter(Tag, I0))
;/* this Tag has not been used as a Key before */
I is 1,
asserta(ref_counter(Tag,I))
).
Note that DEC-10 Prolog accepts integers as Keys (Quintus Prolog imitates
this) and so does this code. However, this code also accepts floats as
Keys, which DEC-10 Prolog and Quintus Prolog don't. I assume that this
doesn't matter.
This implementation is not supposed to be particularly fast, but then
if speed were of the first importance you wouldn't be using a free
compiler. More seriously, the counters may run out, but you should be
able to do ~100 million recordas or recordzs under any given key before
that happens. There are obvious ways around that.
Technical Details
Message-ID:
<2862@goanna.oz.au>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!munnari.oz.au!goanna!okReferences:
<1871@naucse.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!munnari.oz.au!goanna!ok From: ok@goanna.oz.au (Richard O'keefe) Newsgroups: comp.lang.prolog Subject: Re: Public Domain Prolog Interpreters Summary: you don't need one Message-ID: <2862@goanna.oz.au> Date: 13 Feb 90 08:13:40 GMT References: <1871@naucse.UUCP> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 73