NB. Relational Database Definitions first =: {. rest =: }. open =: > box =: < head =: open@first rank =: " bond =: & link =: ; NB. A relation is a collection of tuples which we represent as a table. csg =: ('course';'studentid';'grade');('cs101';12345;'A');('cs101';67890;'B');('ee200';12345;'C');('ee200';22222;'B+');('cs101';333333;'A-');box('ph100';67890;'C+') NB. In the definition of the relation csg we have NB. incorporated additional information attributes (a set of column names called NB. scheme) at the beginning of our representation for a relation. head csg NB. course_studentid_grade scheme rest csg NB. course_studentid_grade relation NB. The order of tuples in a relation is not significant. NB. csg2 =:({. csg) , (? ~ <: # csg) { }. csg NB. is the same relation NB. The order of columns in a relation is not significant. NB. csg1 =: 1 2 0 & { &. > csg NB. csg1 is the same relation NB. We do assume that column names are distinct. NB. access column of a relation by name NB. relation col 'column_name' col =: dyad def '((head x.) i. box y.) bond from rank 1 open rest x.' NB. access row of a relation by row_index NB. relation row row_index row =: dyad def 'open y. from rest x.' NB. Some other sample relations. snap =: ('studentid';'name';'address';'phone');(12345;'C. Brown';'12 Apple St.';'555-1234');(67890;'L. Van Pelt';'34 Pear Ave.';'555-5678');box(22222;'P. Patty';'56 Grape Blvd';'555-9999') cp =: ('course';'prerequisite');('cs101';'cs100');('ee200';'ee005');('ee200';'cs100');('cs120';'cs101');('cs121';'cs120');('cs205';'cs101');('cs206';'cs121');box('cs206';'cs205') cdh =: ('course';'day';'hour');('cs101';'M';'9AM');('cs101';'W';'9AM');('cs101';'F';'9AM');('ee200';'Tu';'10AM');('ee200';'W';'1PM');box('ee200';'W';'10AM') cr =: ('course';'room');('cs101';'Turing Aud.');('ee200';'25 Ohm Hall');box('ph100';'Newton Lab.') NB. A database is a collection of relations NB. Problem 1. Implement relation insert tuple NB. Problem 2. Implement relation delete tuple_spec NB. where '*' in a tuple_spec means match anything. NB. Problem 3. Implement relation lookup tuple_spec NB. where '*' in a tuple_spec means match anything. NB. A key for a relation is a set of one or more attributes such that NB. under no circumstances will the relation have two tuples whose NB. values agree in each column headed by a key attribute. NB. Problem 4. Devise a solution to the kind of problem "What grade did C. Brown NB. receive in cs101?"