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

From: Markus Triska <triska_at_gmx.at>
Date: Sun, 30 Apr 2006 21:03:13 +0200
Message-ID: <445509f0$0$11868$3b214f66_at_tunews.univie.ac.at>


Hi Alvin,

Alvin Ryder wrote:

>> Equating them is wrong.

>
> Why?

Traditional Prolog includes features not considered pure by any stretch of the word (e.g. cut). Nick's examples are easy in traditional Prolog as well. Here is a pure version:

likes(john, [apple,tomato,broccoli]).

thing_is(apple, fruit, yes).
thing_is(apple, vegetable, no).
thing_is(broccoli, vegetable, yes).
thing_is(broccoli, fruit, no).
thing_is(tomato, vegetable, yes).
thing_is(tomato, fruit, no).

filter([], _, []).
filter([Thing|Things], Class, [Thing|Fs]) :-

         thing_is(Thing, Class, yes),
         filter(Things, Class, Fs).
filter([Thing|Things], Class, Fs) :-
         thing_is(Thing, Class, no),
         filter(Things, Class, Fs).

Things John likes:

?- likes(john, Ls).

Ls = [apple, tomato, broccoli]

Fruits John likes:

?- likes(john, Ls), filter(Ls, fruit, Fs).

Fs = [apple]

Vegetables John likes:

?- likes(john, Ls), filter(Ls, vegetable, Vs).

Vs = [tomato, broccoli]

Does John like rice:

?- likes(John, Ls), member(rice, Ls).

No

This is entirely first-order.

All the best,
Markus. Received on Sun Apr 30 2006 - 21:03:13 CEST

Original text of this message