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

From: Neo <neo55592_at_hotmail.com>
Date: 25 Apr 2006 15:14:12 -0700
Message-ID: <1146003252.182469.131490_at_v46g2000cwv.googlegroups.com>


Nick, this example is a slightly extended version of the original Food Judge Example and similar to the Prolog's Ship Contains Coin example. In this judge example, a function named verifyRel, short for "verify relationship" returns true or false for a specified transitive relationship. For example {see end of script}, the expression (verifyRel tomato1 class thing) returns true, since tomato1 class is vegetable/fruit and the class of vegetable/fruit are thing. Function verifyRel also works in the opposite direction, for example the expression (verifyRel thing instance tomato1) return true since thing's instances include fruit/vegetable and fruit/vegetable instances include tomato1. In order for function verifyRel to work in either direction, the script before it has to create bi-directional relationships {ie (create vegetable instance tomato1) and (create tomato1 class vegetable)}. To reduce script size, the function createWRR, short for create with reciprocal relationship, creates the reciprocal relationship if given either. Function createWRR, checks if a particular verb has a reciprocal in the db. For instance, the following relationships already its between verbs class and instance: "class opposite instance" and "instance opposite class". This can be specified for new verbs such as boss/employee. Then createWRR and verifyRel would work bi-directionally with such verbs.

// Food Judge Example B

// Similar to original except
// makes and verify bi-directional transitive relationships.
// Function createWRR creates specified and reciprocal relationship.
// Function verifyRel verifies transitive relationships.

// Create a thing named person.

(createWRR thing instance (new))
(create (it) name (findElseAdd word instance 'person'))

// Create a thing named judge.

(createWRR thing instance (new))
(create (it) name (findElseAdd word instance 'judge'))

// Create a person/judge named john.

(createWRR person instance (new))
(createWRR judge instance (it))
(create (it) name (findElseAdd word instance 'john'))

// Create a verb named like.
(createWRR verb instance (new))
(create (it) name (findElseAdd word instance 'like'))

// Create a thing named entry (as in food entry).
(createWRR thing instance (new))
(create (it) name (findElseAdd word instance 'entry'))

// Create an entry named leftOver1.
(createWRR entry instance (new))
(create (it) name (findElseAdd word instance 'leftOver1'))

// Create a thing named fruit.

(createWRR thing instance (new))
(create (it) name (findElseAdd word instance 'fruit'))

// Create a fruit/entry named apple1.

(createWRR fruit instance (new))
(createWRR entry instance (it))
(create (it) name (findElseAdd word instance 'apple1'))

// Create a thing name vegetable.
(createWRR thing instance (new))
(create (it) name (findElseAdd word instance 'vegetable'))

// Create a vegetable/entry named broccoli1.

(createWRR vegetable instance (new))
(createWRR entry instance (it))
(create (it) name (findElseAdd word instance 'broccoli1'))

// Create a fruit/vegetable/entry named tomato1.

(createWRR fruit instance (new))
(createWRR vegetable instance (it))
(createWRR entry instance (it))
(create (it) name (findElseAdd word instance 'tomato1'))

// Create john likes leftOver1.
(create john like leftOver1)

// Create john likes apple1.
(create john like apple1)

// Create john likes broccoli1.
(create john like broccoli1)

// Create john likes tomato1.
(create john like tomato1)

// Find which entries john likes.
// Either of the below expressions
// displays leftOver1, apple1, broccoli1, tomato1
// in 4 consecutive dialog boxes.
(msgbox (select john like *))
(msgbox (and (select john like *)

             (select entry instance *)))

// Find which fruit entries john likes.
// Displays apple1 and tomato1.
(msgbox (and (select john like *)

             (select fruit instance *)))

// Find which vegetable entries john likes.
// Displays broccoli1 and tomato1.
(msgbox (and (select john like *)

             (select vegetable instance *)))

// Find which fruit/vegetable entries john likes.
// Displays tomato1 in a dialog box.

(msgbox (and (select john like *)
             (select fruit instance *)
             (select vegetable instance *)))


// Verify Transitive Relationships:

// Is tomato1 is a vegetable?
// Displays true.

(msgbox (verifyRel tomato1 class vegetable))

// Is tomato1 is a fruit?
// Displays true.

(msgbox (verifyRel tomato1 class fruit))

// Is tomato1 is a thing?
// Displays true.

(msgbox (verifyRel tomato1 class thing))

// Is tomato1 is a person?
// Displays false.

(msgbox (verifyRel tomato1 class person))

// Is tomato1 is an instance of vegetable?
// Displays true.

(msgbox (verifyRel vegetable instance tomato1))

// Is tomato1 is an instance of fruit?
// Displays true.

(msgbox (verifyRel fruit instance tomato1))

// Is tomato1 is an instance of thing?
// Displays true.

(msgbox (verifyRel thing instance tomato1))

// Is tomato1 is an instance of person?
// Displays false.

(msgbox (verifyRel person instance tomato1)) Received on Wed Apr 26 2006 - 00:14:12 CEST

Original text of this message