Re: Question from a Prolog dummy
- From: Nick Wedd <nick@xxxxxxxxxxxxx>
- Date: Sat, 7 Jul 2007 10:02:50 +0100
In message <1183779708.808860.126330@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, nowhereface@xxxxxxx writes
"jane" as such is not stored anywhere. What is stored is the various
facts such as 'happy(jane)'. And these are stored under the predicate
that they are facts for - in this case, under happy/1. [They are
probably stored as a linked list for happy/1 - but they might not be,
and anyway it should be no concern of the programmer.]
It is of concern to me because I am interested in how languages work,
and a list implementation is slow as mollasses compared to a hash
implementation. Of course, I'm not overly-concerned with speed - if I
were I'd do all my programming in C or assembler. But I was curious,
if nothing else.
Unless I'm missing something, it would seem that these predicates are
implemented as hashes, at least in performance/commercial high-end
systems.
When I worked on Prolog implementation, over 20 years ago, the default was no hashing. (This was ESI's Prolog-2.) But you could switch on hashing, on the functor and arity of the first argument of the hashed predicate: so if you hashed
likes( jane, fred ).
likes( jane, tom ).
likes( fred, bananas ).
likes( both(amy,alice), cheese ).
the values hashed would be jane/0, jane/0, fred/0, both/2.
I'm sure things have moved on since then.
A predicate can't _just_ be a hash. The order of the clauses matters.
Nick
--
Nick Wedd nick@xxxxxxxxxxxxx
.
- References:
- Question from a Prolog dummy
- From: nowhereface
- Re: Question from a Prolog dummy
- From: Nick Wedd
- Re: Question from a Prolog dummy
- From: nowhereface
- Question from a Prolog dummy
- Prev by Date: Re: Question from a Prolog dummy
- Next by Date: DCGs from streams
- Previous by thread: Re: Question from a Prolog dummy
- Next by thread: Re: Question from a Prolog dummy
- Index(es):
Relevant Pages
|
|