how can I find a list from given database??
Database:
(10 math phys)
(11 math chem)
(13 bio chem)
(15 geo phys)
I want to implement time which shows the first and second exams in a list.
>(time ’10)
(list ‘math ‘phys)
>(time ’19)
empty
And I want to implement secondExams which returns the time of second exams.
>(secondExams ‘phys)
(list ‘10 ’15)
>(secondExams ‘chem)
(list ’11 ’13)
thank you
First, let’s clarify your database format. Make it a list of lists:
Then time just needs to step through your list recursively, and compare the first element of the sub-list with your target value. If we find no matching value, we’ll return the empty list. We’ll do this in a helper procedure to match the functionality you’re precisely seeking.
Then we can do something very similar for secondExams. Except we’ll recursively build a list of matches this time.
I haven’t tested this code, but I’m pretty sure it’ll work for you.