This dbd example models pilots who fly jets.
Queries with selectAll find pilots who fly all jets.
For details, see www.dbfordummies.com/example/ex042.asp
(new 'fly 'verb)
(new 'jet1 'jet)
(new 'jet2 'jet)
(new 'pilot1 'pilot)
(create pilot1 fly jet1)
(new 'pilot2 'pilot)
(create pilot2 fly jet1)
(create pilot2 fly jet2)
(; Find pilots who fly all jets)
(; Finds pilot2)
(and (select pilot instance *)
(selectAll * fly (select jet instance *)))
(new 'jet3 'jet)
(new 'pilot3 'pilot)
(create pilot3 fly jet1)
(create pilot3 fly jet2)
(create pilot3 fly jet3)
(; Find pilots who fly all jets)
(; Finds pilot3)
(and (select pilot instance *)
(selectAll * fly (select jet instance *)))
(new 'red 'color)
(create jet1 color red)
(new 'green 'color)
(create jet2 color green)
(new 'blue 'color)
(new 'purple 'color)
(create jet3 color blue)
(create jet3 color purple)
(; Find pilots who fly all jets that are red)
(; Finds pilot1, pilot2 and pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color red))))
(; Find pilots who fly all jets that are green)
(; Finds pilot2 and pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color green))))
(; Find pilots who fly all jets that are blue and purple)
(; Finds pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color blue)
(select * color purple))))
(; Find pilots who fly all jets that are red or green)
(; Finds pilot2 and pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color (or red green)))))
(; Find pilots who fly all jets that are not red or green)
(; Finds pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color (not red green)))))