Managing Dynamic Data Structures with Lightweight Database



Below example script, C and VB code show how to manage dynamic data
structures with a lightweight, memory-resident database. During the
1st run, it creates john and mary, each with gender attributes. During
the 2nd run, it creates bob with gender and age attributes. It also
adds age attribute to existing john. During 3rd run, it adds the
attribute body-build-type to mary and bob. Note that attribute build
can have multiple values. During the 4th run, it creates sue with all
attributes using low-level functions. It also modifies john's age and
deletes one of mary's build attribute values. At the end of each C/VB
run, prints persons, attributes and their values stored in db. The
script is submitted via a small GUI front end (250 Kb). The C and VB
code interface to the db via a Windows DLL (128 Kb). The data is
stored in a single file. For more details, see www.dbfordummies.com

(; * 1st run *)
(new 'gender)

(; Create a person named john and set his gender to male)
(new 'john 'person)
(set+ john gender 'male)

(; Create a person named mary and set her gender to female)
(new 'mary 'person)
(set+ mary gender 'female)


(; * 2nd run *)
(new 'age)

(; Create a person named bob)
(; Set his gender to male and age to 35)
(new 'bob 'person)
(set+ bob gender 'male)
(set+ bob age '35)

(; Set john's age to 30)
(set+ john age '30)

(; Get all person that are male)
(; Gets john and bob)
(and (get person instance *)
(get * gender male))


(; * 3nd run *)
(new 'build)

(; Set bob's build to tall)
(set+ bob build 'tall)

(; Set mary's build to thin and petite)
(set+ mary build 'thin)
(set+ mary build 'petite)


(; * 4th run *)
(; Create a person named sue, gender female, age 21)
(new 'sue 'person)
(set+ (it) gender 'female)
(set+ (it) age '21)
(set+ (it) age '21)

(; Set sue's build to fat and short)
(set+ sue build 'fat)
(set+ sue build 'short)

(; Change john's age from 30 to 40)
(new '40 'age)
(change (get john age 30) 40)

(; Delete mary's build is thin)
(delete (get mary build thin))

.



Relevant Pages