Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Storing data and code in a Db with LISP-like interface

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

From: Neo <neo55592_at_hotmail.com>
Date: 28 Mar 2006 19:40:38 -0800
Message-ID: <1143603638.582373.250560@i40g2000cwc.googlegroups.com>


Below is an example script for an experimental db (in development) that can store both data and code.

Unlike typical databases, data is not stored using a table/record methodology, but via nodes where each node can connect to any other node, in a manner similar to neurons in the human brain.

Unlike typical databases which use an SQL interface, the experimental db has a LISP-like interface. In general each expression or statement starts with "(" and end with ")". Within the parenthesis there can be any number of elements. The first element is the command or function. The remaining elements are function parameters. The core functions currently are create, select, delete and update. Any element can itself be itself be a sub expression and elements of the sub expression can also be a sub expression and so on forever (theorectically).

The db assumes that anything can have 0 to many names. And a name can have 0 to many representations such as a string of ascii symbols, chinese symbols, sounds, etc (only ascii symbols are implemented currently).

Because of the high degree of separation between the logical and physical layers and the extreme flexibility of the db, the amount of memory and processing power required are limiting factors (currently).

The script below (best viewed in fixed size font) creates some cars and people. The first function (stored in db) loops thru things that john likes. The second function displays instances of class specified as a parameter. Functions can create local variables which are stored on a "stack" which is also in the db and functions (system or user-defined) are re-entrant.

Any constructive comments appreciated.

// ----------------------------------------------------
// SIMPLE CAR EXAMPLE
// Create car named rx7.

// Create a new name with symbols 'car'

(create name instance (new))
(create (it) symbol (create 'c' 'a' 'r'))

// Create a new type named car.

(create type instance (new))
(create (it) name (and (select name instance *)

                       (select * symbol (select 'c' 'a' 'r'))
                  )

)

// Create a new name with symbols 'rx7'.
(create name instance (new))
(create (it) symbol 'rx7') // Note: 'rx7' is a shortcut.

// Create a new car named rx7.

(create car instance (new))
(create (it) name (select * symbol 'rx7'))

// Create a new car named accord.

(create car instance (new))
(create (it) name (findElseCreate name instance 'accord'))

// ------------------------------------------------------
// Create code that will create a car named neon.
// Uncheck "Execute Expression Immediately" from Tool Menu
// before submitting below expressions.
// Thus, each expression is stored and not executed
// until user selects appropriate tree node
// and then issues execute code command from Tool Menu.

// Create a new car named neon.

(block

     // Create new name with symbols 'neon'
     (create name instance (new))
     (create (it) symbol (create 'n' 'e' 'o' 'n'))

     // Create new car with above name
     (create car instance (new))
     (create (it) name (and (select name instance *)
                            (select * symbol (select 'n' 'e' 'o' 'n'))
                       )
     )

)
// Now select appropiate node in db and select execute from Tools Menu.

// --------------------------------------------------------------
// EXAMPLE with john, mary and a cat named mary also.
// --------------------------------------------------------------

// Create type gender.

(create type instance (new))
(create (it) name (findElseCreate name instance 'gender'))

// Create gender male.

(create gender instance (new))
(create (it) name (findElseCreate name instance 'male'))

// Create gender female.

(create gender instance (new))
(create (it) name (findElseCreate name instance 'female'))

// Create type person.

(create type instance (new))
(create (it) name (findElseCreate name instance 'person'))
(create dir item (it))

// Create a person named John whose gender is male.

(create person instance (new))
(create (it) name (findElseCreate name instance 'john'))
(create (it) gender (findElseCreate gender instance 'male'))

// Create a person named Mary whose gender is female.

(create person instance (new))
(create (it) name (findElseCreate name instance 'mary'))
(create (it) gender (findElseCreate gender instance 'female'))

// Create a person named Sue.

(create person instance (new))
(create (it) name (findElseCreate name instance 'sue'))

// Create verb like.

(create verb instance (new))
(create (it) name (findElseCreate name instance 'like'))

// Create verb hate.

(create verb instance (new))
(create (it) name (findElseCreate name instance 'hate'))

// Create John like Mary.

(create john like mary)

// Create John like Sue.

(create john like sue)

// What does John like that is a person and female?
// Ans: Mary the person.

(msgbox (and (select john like *)
             (select person instance *)
             (select * gender female)
        )

)

// Create type cat.

(create type instance (new))
(create (it) name (findElseCreate name instance 'cat'))
(create dir item (it))

// Create a cat named Mary.

(create cat instance (new))
(create (it) name (findElseCreate name instance 'mary'))
(create (it) gender female)

// Create John like the cat named Mary.

(create john like (and (select cat instance *)

                       (select * name (select * symbol 'mary'))
                  )

)

// What does john like that is female?
// Ans: Mary the person and Mary the cat.
(msgbox (and (select john like *)

             (select * gender female)
        )

)

// Create Mary the cat hates all persons (John and Mary).
// Note: Currently following only creates relation to John.
// Code should also make relation to person Mary, but doesn't.
(create (and (select cat instance *)

             (select * name (select * symbol 'mary'))
        )
        hate
        (select person instance *)

)

// What does Mary the cat hate?
// Ans: Persons named John [and Mary].

(msgbox (select (and (select cat instance *)

                     (select * name (select * symbol 'mary'))
                )
                hate
                *
        )

)

// If John like Mary
// Then print true
// Else print false

(if (select john like mary)
    (msgbox true)
    (msgbox false)

)

// If John equals Mary,
// Then print true
// Else print false

(if (equal john mary)
    (msgbox true)
    (msgbox false)

)

// If John equals first instance of person who is male,
// Then print true
// Else print false

(if (equal john

           (and (select person instance *)
                (select * gender male)
           )

    )
    (msgbox true)
    (msgbox false)
)

// If Sue equals last instance of person,
// Then print true
// Else print false

(if (equal sue

           (lastNode (select person instance *))     )
    (msgbox true)
    (msgbox false)
)

// Change gender of things named Mary from female to male.
// In effect, changes the gender of Mary the person and the cat to
male.
(update (select (select * name (select * symbol 'mary'))

                gender
                female
        )
        male

)

// Change person Mary's gender from male to female.
(update (select (and (select person instance *)

                     (select * name (select * symbol 'mary')))
                gender
                male
        )
        female

)

// -----------------------------------------------------------
// Below script creates a function named func1
// to find things that john likes and displays them in a msgbox.
// Function func1 is stored in db.

// Create func1.

(create function instance (new))
(create (it) name (findElseCreate name instance 'func1'))

// Disable expr execution from Tools Menu.
(func1 code

       (block
         (createVar 'myQ1')
         (create (selectVar 'myQ1') refersTo (qryStore (select john
like *)))
         (createVar 'var1')
         (create (selectVar 'var1') refersTo (qryGetNext (qryRecall
(selectVarVal 'myQ1'))))
         (while (selectVarVal 'var1')
                (block
                  (msgbox (selectVarVal 'var1'))
                  (delete (select (selectVar 'var1') refersTo))
                  (create (selectVar 'var1')
                          refersTo
                          (qryGetNext (qryRecall (selectVarVal
'myQ1'))))
                )
         )
       )

)

// Enable expression execution from Tools Menu and execute func1.
// Note that func1 can now be invoked just like system functions
// such as create, select, delete and update.
(func1)

//--------------------------------------------------

// Create a function named displayInstances which has a parameter.
// The parameter specifies which class's instances to display in
msgbox.
(create function instance (new))
(create (it) name (findElseCreate name instance 'displayInstances'))
(create (it) parameter 'class')

// Disable expr execution from Tools Menu.
(displayInstances

   code
   (block

         (create (createVar 'myQry')
                 refersTo
                 (qryStore (select (selectVarVal 'class') instance *)))
         (create (createVar 'instX')
                 refersTo
                 (qryGetNext (qryRecall (selectVarVal 'myQry'))))
         (while (selectVarVal 'instX')
                (block
                  (msgbox (selectVarVal 'instX'))
                  (delete (select (selectVar 'instX') refersTo))
                  (create (selectVar 'instX')
                          refersTo
                          (qryGetNext (qryRecall (selectVarVal
'myQry'))))
                )
         )

   )
)

// Enable expression execution from Tools Menu
// and execute function with a parameter.

(displayInstances person)  // Displays john, mary, sue.
(displayInstances cat)     // Displays Mary.
(displayInstances car)     // Displays rx7, accord, neon.



// NOTES



In scripts, (it) refers to the thing created by last (new) in current scope.

When a script containing 'xyz' is processed, str 'xyz' is created it in db, even if it does not exist.
This is done to reduce length/complexity of scripts that occurs in script for car named neon.

'xyz' => (select 'x' 'y' 'z')

xyz => (firstNode (select *

                           name
                           (firstNode (and (select name instance *)
                                           (select * symbol 'xyz')
                                      )
                           )
                   )
        )

(findElseCreate name instance 'bob') =>

    (if (and (select name instance *)

             (select * symbol 'bob')
        )

        // Then
        (return (select * symbol 'bob'))

        // Else
        (block
          (create name instance (new))
          (create (it) symbol (create 'b' 'o' 'b'))
          (return (it))
        )

    )

// Creates a variable on the stack for current instance of
block/function.
(createVar 'var1') => (block

                        (create (new) name (findElseCreate name
instance 'var1'))
                        (create (select stackPtr refersTo *) variable
(it))
                      )

// Selects a variable on the stack for current instance of
block/function.
(selectVar 'var1') => (and (select (select stackPtr refersTo *) variable *)

                           (select * name (select * symbol 'var1'))
                      )

// Selects the "value" of a variable on the stack.
(selectVarVal 'var1') => (select (selectVar 'var1') refersTo *) Received on Tue Mar 28 2006 - 21:40:38 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US