Re: Storing data and code in a Db with LISP-like interface
Date: 25 Apr 2006 21:37:36 -0700
Message-ID: <1146026256.838345.241580_at_y43g2000cwc.googlegroups.com>
Neo wrote:
>
> mAsterdam, you surprise me! You also have Prolog running thru your
> veins! How many other Prologers are hiding amongst us?
I am not a prologer by any stretch. I took a class from Lofti Zadeh as part of my university coursework over 20 years ago; I vaguely remember it was in prolog. But in the last few years as I've gotten more interested in logic and relational theory, I came to the conclusion that I ought to know at least a little prolog. Have read up some on Mercury as well.
I will pass over your questions which involve using variables in place of predicates. I am in a little over my head here, but I believe a number of your questions require second order logic.
http://en.wikipedia.org/wiki/Second_order_logic
> 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?
I think you are correct that "person(john)" is the canonical
way to specify that john satisfies the predicate "person."
> Find a person who likes a fruit and a vegetable.
> (Assume there are more persons).
> For example in dbd, it would be:
>
> (and (select person instance *)
> (select * like (and (select vegetable instance *)
> (select fruit instance *)
> )
> )
> )
Even my lame prolog skills are up to that question. Especially since mAsterdam did all the typing already. Hmmm. SWI-Prolog comes from ... Amsterdam? Hmmm.
"Find X where X is a person, X likes V, V is a vegetable, X likes F, and F is a fruit."
bash-3.1$ pl
Welcome to SWI-Prolog (Multi-threaded, Version 5.2.6)
Copyright (c) 1990-2003 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- consult('neo.pro').
% neo.pro compiled 0.00 sec, 2,104 bytes
Yes
?- person(X),likes(X,V),vegetable(V),likes(X,F),fruit(F).
X = john V = tomato1 F = apple1 ; X = john
V = tomato1
F = tomato1 ;
No
?-
Amusingly, since we have specified that the tomato is both a fruit and a vegetable, anyone who likes tomatoes will qualify, as we see above. However, the reader is strongly cautioned! The tomato is *not* a vegetable!
To me, perhaps the most interesting thing about prolog is the trivial ease with which one can write the ancestor query, which causes such consternation for SQL.
Marshall Received on Wed Apr 26 2006 - 06:37:36 CEST