Re: Storing data and code in a Db with LISP-like interface

From: mAsterdam <mAsterdam_at_vrijdag.org>
Date: Wed, 26 Apr 2006 09:16:14 +0200
Message-ID: <444f1e24$0$31644$e4fe514c_at_news.xs4all.nl>


Neo wrote:

>>--------------------
>>person(john).
>>judge(john).
>>fruit(apple1).
>>fruit(tomato1).
>>vegetable(tomato1).
>>vegetable(broccoli1).
>>likes(john, leftover1).
>>likes(john, apple1).
>>likes(john, tomato1).
>>
>>thing(X):-vegetable(X).
>>thing(X):-fruit(X).
>>----------------------

>
>
> mAsterdam, you surprise me!
> You also have Prolog running thru your veins!

To much honour. It is very rusty, but when I saw your statements I thought: /this/ is much easier in prolog. I wanted to check that.

> How many other Prologers are hiding amongst us?
>
>

>>You really should play a little with prolog:

>
>
> Yes, Prolog does look very interesting (and compact). I am sure I could
> learn a lot from it, especially it terms of logical processing; however
> for now I am focused on developing the most general/flexible method of
> representing things. Let us see if Prolog is further along than I am
> with comming example extensions :)
>
>
>>person(john)

>
>
> If "likes (john, apple1)" implies "john likes apple1"
> why isn't "john isa person" written as "isa (john, person)"
> or is "person (john)" an alternate/equivalent method?

Re-engineering your program forced me to do some interpretation.

"person(john)."
looked to me as a reasonable prolog representation for "john isa person". It may be that there are some subtleties in "isa" it did not catch. You might provide some tests.

> If so, what is or how does one determine the name of the relationship
> via code?
>
> If "isa (john, person)" and "instance (person, john)" are possible,
> can I relate isa and instance?

In several ways.

You really should play with prolog yourself for a while. In the cycle " your ideas - your statements - my interpretation - my coding - your interpretation of the results" there is much more room for bogus than in "your ideas - your coding - your interpretation of the results".

> Can I write "opposite (isa, instance)" and "opposite (instance, isa)"?

Not sure what you mean here.

> Can functions be parameters of other functions?

Yes, second order logic is possible.
>

>>thing(X):-vegetable(X).

>
>
> Based on my limited knowledge of Prolog, it is not clear if vegetable
> it is not clear if vegetable
> isa thing.

Not according to this clause. This clause could read as: If X is a vegetable, it is a thing.

> isa thing. What does the following return?
>
> ?- thing(vegetable).
With the current database(=program)
I would expect prolog to return "No".

>>3 ?- likes(john, What).

>
>
> Ok, I see "What" is like a variable that can hold many things.
> The "What" is similar to the "*" in dbd and SQL.

That is not the way I see a prolog variable. It is more like a placeholder for part of a result set.

> How do I express the following query in Prolog:
> Find a person who likes a fruit and a vegetable.
> (Assume there are more persons).

Against the same neof.pro:

8 ?- person(P), likes(P, F), likes(P, V), fruit(F), vegetable(V).

P = john
F = apple1
V = tomato1 ;

P = john

F = tomato1
V = tomato1 ;

No

> For example in dbd, it would be:
>
> (and (select person instance *)
> (select * like (and (select vegetable instance *)
> (select fruit instance *)
> )
> )
> )
>
>
> If you (or someone) can update the Prolog example and bring it closer
> to dbd's, that would be great (so we can extend them later):
> 1) add missing entry classification.
> 2) add instance relationship between various things.
> 3) create relationship between instance and isa as in "isa opposite
> instance" and "instance opposite isa". Note: the dbd script doesn't
> show this since it is already created in each new db, however I can
> perform queries to show the relationship exists.
> 4) classify likes as a verb.
> 5) add the missing queries, if possible.
>
> In later example extensions, I'd like to address:
> Can one add attributes to "likes" in Prolog?

Did you try?

> Can one add a synonym for "likes"?
> Can Prolog handle a thing with multiple name?
> For example, can I name the judge both john and johnathan?
> Can Prolog handle two persons named john but with different SS#?
> Can Prolog handle a person without a name but a SS#?
> Can Prolog handle the same things in multiple hierarchies?
> Are things normalized?
>
Received on Wed Apr 26 2006 - 09:16:14 CEST

Original text of this message