How to Add Records to the PicoLisp Database

Create a new database

$ pil family-dbmodel.l +: (pool "myFamily.db")
-> T
: (show *DB)
{1} NIL
-> {1}

Inserting some data using the request function

: (request '(+Man) 'name "Adam")
-> {2}
: (request '(+Woman) 'name "Eve")
-> {6}

Querying the data

: (show *DB)
{1} NIL
+Person {3}
+Woman {7}
+Man {4}
-> {1}
: (collect 'name '+Person)
-> ({2} {6})
: (show '{2})
{2} (+Man)
name "Adam"
-> {2}
: (more (collect 'name '+Person) show)
{2} (+Man)
name "Adam"
{6} (+Woman)
name "Eve"
: (commit)
T

Defining the relationships

: (put!> '{2} 'partner '{6})
-> {6}
: (show '{2})
{2} (+Man)
partner {6}
name "Adam"
-> {2}
: (show '{6})
{6} (+Woman)
partner {2}
name "Eve"
-> {6}

Some more entries

: (request '(+Man) 'name "Kain" 'job "farmer" 'father '{2} 'mother '{6})
-> {12}
: (request '(+Man) 'name "Abel" 'job "shepherd" 'father '{2} 'mother '{6})
-> {14}
: (request '(+Man) 'name "Seth" 'father '{2} 'mother '{6})
-> {15}
: (commit)
-> T
: (show '{2})
{2} (+Man)
kids ({15} {14} {12})
partner {6}
name "Adam"
-> {2}
: (more (get '{2} 'kids) show)
{15} (+Man)
mother {6}
father {2}
name "Seth"
{14} (+Man)
mother {6}
father {2}
job "shepherd"
name "Abel"
{12} (+Man)
mother {6}
father {2}
job "farmer"
name "Kain"

Validation checks

(rel birthday (+Ref +Date))
: (put> '{2} 'birthday "Genesis")
-> "Genesis"
: (show '{2})
{2} (+Man)
birthday "Genesis"
kids ({15} {14} {12})
partner {6}
name "Adam"
-> {2}
: (mis> '{2} 'birthday "Genesis")
-> "Numeric input expected"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mia Temma

Mia Temma

These are cross-posts from my blog https://picolisp-explored.com. I’m writing about PicoLisp for beginners. Welcome!