Modelling Persons, Devices and Phone Numbers with dbd

From: Neo <neo55592_at_hotmail.com>
Date: 13 Nov 2006 16:06:31 -0800
Message-ID: <1163462791.798198.33220_at_h48g2000cwc.googlegroups.com>



The following script demos an experimental db's ability to manage data. In this example, persons have communication devices of various types which have phone numbers. For overview, skim comments which begin with "(; ". For a similar but simpler example, see www.dbfordummies.com/example/ex003.asp

(; Create various initial classifications)
(new 'person)
(new 'has 'verb)
(new 'device)
(new 'phone)
(new 'fax)
(new 'number)

(; Create a phone/device whose number is 111-1111)
(new 'ph1 'phone 'device)
(new '111-1111 'number)
(create ph1 number 111-1111)

(; Create a fax/device whose number is 222-2222)
(new 'fax2 'fax 'device)
(new '222-2222 'number)
(create fax2 number 222-2222)

(; Create a person named john who has ph1 and fax2)
(new 'john 'person)
(create john has ph1)
(create john has fax2)

(; Create a person named mary who has

   a phone/device whose number is 333-3333    and a fax/device whose number 444-4444)
(new 'mary 'person)
(create mary has (block (new 'ph3 'phone 'device)

                    (create (it) number (val+ '333-3333))
                    (return (it))))

(create mary has (block (new 'fax4 'fax 'device)
(create (it) number (val+ '444-4444)) (return (it))))

(; Find persons who has a thing whose number is 111-1111)
(; Returns john)
(and (select person instance)

     (select * has (select * number 111-1111)))

(; Find things which has a device whose number is 111-1111)
(; Returns john)
(select * has (and (select device instance *)

                   (select * number 111-1111)))

(; Find things which has a phone whose number is 111-1111)
(; Returns john)
(select * has (and (select phone instance *)

                   (select * number 111-1111)))

(; Find things which has a thing whose number is 444-4444)
(; Returns mary)
(select * has (select * number 444-4444))

(; Update john's thing's number from 111-1111 to 111-0000)
(new '111-0000 'number)
(update (select (select john has *) number 111-1111)

        111-0000)

(; Update mary's fax's number from 444-4444 to 444-0000)
(new '444-0000 'number)
(update (select (and (select fax instance *)

                     (select mary has *))
                number 444-4444)
        444-0000)

(; New data requirement.

   John has a mobile/device whose number is 555-5555)
(new 'mb5 'mobile 'device)
(new '555-5555 'number)
(create mb5 number 555-5555)
(create john has mb5)

(; New data requirement.

   Mary has a cell/device whose number is 666-66666)
(create mary has (block (new 'cell6 'cell 'device)

                    (create (it) number (val+ '666-6666))
                    (return (it))))

(; New data requirement.

   John has a second phone whose number is 777-7777)
(create john has (block (new 'ph7 'phone 'device)

                    (create (it) number (val+ '777-7777))
                    (return (it))))

(; Find john's thing's numbers)
(; Returns 111-0000, 222-2222, 555-5555 and 777-7777)
(select (select john has *) number *)

(; Update john's second phone's number

   from 777-7777 to 777-0000)
(update (select (select john has *) number 777-7777)

        (new '777-0000 'number))

(; New data requirement.

   Create a phone/fax device model# C2890A with 2 numbers    that belongs to both john and mary)
(new 'phFx89 'phone 'fax 'device)
(new 'C2890A 'model#)
(create phFx89 model# C2890A)
(new '888-8888 'number)
(create phFx89 number 888-8888)
(new '999-9999 'number)
(create phFx89 number 999-9999)
(create john has phFx89)
(create mary has phFx89)

(; Find numbers that belongs to things

   that belongs to both john and mary)
(; Returns 888-8888 and 999-99999)
(and (select (select john has *) number *)

     (select (select mary has *) number *))

(; Find numbers of things that john has)
(; Returns 111-0000, 222-2222, 555-555,

   777-0000, 888-8888, 999-9999)
(select (select john has *) number *)

(; Find numbers of phones that john has)
(; Returns 111-0000, 222-2222, 555-555,

   777-0000, 888-8888, 999-9999)
(select (and (select john has *) (select phone instance *))

        number *)

(; Find things which have a thing whose model# is C2890A)
(; Returns john and mary)
(select * has (select * model# C2890A))

(; Find persons who have a phone/fax whose model# is C2890A)
(; Returns john and mary)
(and (select person instance *)

     (select * has (and (select phone instance *)
                        (select fax instance *)
                        (select * model# C2890A))))

(; New data requirement.

   Phone/fax named phFx89 fowards to phone named ph1    and it forwards to mobile phone named mb5)
(new 'forwardsTo 'verb)
(create ph1 forwardsTo mb5)
(create mb5 forwardsTo cell6)
(create cell6 forwardsTo phFx89)
Received on Tue Nov 14 2006 - 01:06:31 CET

Original text of this message