Re: Question from a Prolog dummy



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
.



Relevant Pages

  • Re: A different way to optimize this?
    ... and has now grown quite large in the number of facts it represents. ... It's a single argument predicate of the style shown below (this is not ... The number of facts in foo/1 grew to several hundred. ... % Try three word sequence. ...
    (comp.lang.prolog)
  • Re: Question from a Prolog dummy
    ... And these are stored under the predicate ... that they are facts for - in this case, under happy/1. ... and a list implementation is slow as mollasses compared to a hash ...
    (comp.lang.prolog)
  • Re: Database design, Keys and some other things
    ... That is the sentence, with the predicate in square brackets. ... 'metadata' is woefully blurry, and given all data may be metadata and vice versa, its somewhat of a meaningless concept. ... Databases and databased thinking help when ... facts about facts. ...
    (comp.databases.theory)
  • Re: Howto access to a prolog database
    ... if this really a prolog database, it might be expressed as a set of facts of a given arity (think about tables in a spreadsheet, each line corresponds to a predicate (ie fact) and each cell of this line to one argument of this predicate). ... would be a listing wich will print all recorded facts. ...
    (comp.lang.prolog)
  • Re: Another view on analysis and ER
    ... desires) something as a thing, as in Exists x, or as a predicate, X. ... So if I have my previous example "John from London married Jane from ... has at least one lexical representation and is ... Note by the way that if you want to define propositions that way then ...
    (comp.databases.theory)