Re: Multiple-Attribute Keys and 1NF

From: Neo <neo55592_at_hotmail.com>
Date: Tue, 28 Aug 2007 13:25:43 -0700
Message-ID: <1188332743.734645.58770_at_d55g2000hsg.googlegroups.com>


> ... theoretical underpinning for 1NF.
>
> Brown -> live.
> Red -> live
> Blue -> neutral.
> Black -> neutral.
> Green and yellow -> earth.

Below is one possible solution using dbd:

(new 'brown 'color)
(new 'red 'color)
(new 'blue 'color)
(new 'black 'color)
(new 'green 'color)
(new 'yellow 'color)

(new 'wire1 'wire 'live_wire)
(set wire1 color brown)

(new 'wire2 'wire 'live_wire)
(set wire2 color red)

(new 'wire3 'wire 'neutral_wire)
(set wire3 color blue)

(new 'wire4 'wire 'neutral_wire)
(set wire4 color black)

(new 'wire5 'wire 'earth_wire)
(set wire5 color green)
(set wire5 color yellow)

(; Get wires that are brown)
(; Gets wire1)
(get * color brown)

(; Get wires that are red)
(; Gets wire2)
(get * color red)

(; Get wires that are both brown and red)
(; Gets nothing)
(& (get * color brown)

    (get * color red))

(; Get wires that are both green and yellow)
(; Gets wire5)
(& (get * color green)

    (get * color yellow))

DBD MINI TUTORIAL:
Unlike the CODASYL network data model which is infact a hybrid relational/hierarchal data model, dbd (database for dummies) represents things with a network of nodes where each node implements the fundamental unit of computation: the AND gate or a switch. A user models a thing by creating a node and relating it to existing nodes in db. Each db is initialized with nodes for basic things such as symbols and common classes. Besides GUI/API, a user communicates with the db via expressions. The general syntax of an expression is "(func [inp1] [inp2] ...)". Each expression begins with a "(" and ends with corresponding ")". The first element after "(" is the function. Basic functions inclue new, set, get, change and delete. The remaining elements, if any, are function inputs. An element of an expression can itself be a subexpression. Expressions starting with "(;" are comments. The expression "(new)" creates a new node in the db. The expression "(it)" refers to the last node created by "(new)". To relate a node, say to a string (sequence of symbols), use the expression "(set (it) name 'john)". Note that a string is indicated by preceeding it with a single quote. Once a node has been named by a string, it can be referenced by its name. See following example:

(; Create a node for a person to be named by the string 'john)
(new)

(; Relate new node to its name, the string 'john)
(set (it) name 'john)
(; We can now reference new node by simply by john)

(; Now we want to make john an instance of person)
(; Create new node for person)
(new)

(; Relate its name as the string 'person)
(set (it) name 'person)

(; In order to view item in GUI, relate new class to tree root)
(set db item person)

(; Set john is an instance of person)
(set person instance john)

(; The following expression is equivalent to that above)
(; The subexpressions solved for *,

   prior to executing the main expression)
(set (get * name 'person) instance (get * name 'john))

(; create a person/doctor named mary using shortcut method)
(; Note that the new function's

   input1 is the name of the new node
   and remaining inputs classify it)
(new 'mary 'person 'doctor)

For more details, see www.dbfordummies.com Received on Tue Aug 28 2007 - 22:25:43 CEST

Original text of this message