A calendar language - Some calendar functions ****
Design a small Lisp language (in Scheme) for calendars and appointments. A calendar can contain a number of appointments.
An appointment is characterized by an appointment text, a starting time and an ending time.
Times have the usual constituents: Year, month, day, hour, and minute.
A calendar can also contain other calendars recursively (as in a Composite design pattern).
In addition to the design of the Lisp Calendar language, you are requested to write a number of processing functions, including a function
that presents a calendar in HTML.
In this assignment we distinguish between:
- A calendar expression, which makes use of a number of constructor functions (for the calendar as such, for each appointment, for starting time, ending time, etc).
Each such construction function should accept flexible parameters, and it should check its constituents such that a constructed calendar/appointment is guaranteed to be well-formed.
The constructor functions should return an internal representation (see below).
There must be functions that access the parts of a calendar, the parts of an appointment, the parts of a time, etc.
- An internal representation, as generated by the constructor functions. Feel free pick an internal representation which fits your needs and preferences.
You may prefer to think of the internal representation as an abstract syntax tree of the calendar language.
Please, in particular, consider how to represent time in your calendar.
The internal representation may reflect the calendar expressions rather directly, or it may reorganize the calendar in a way which fits the operational needs (see below).
- One or more external presentations. In this assignment we will produce a simple HTML presentation of the calendar (see below).
You are asked to program the following functionality on calendars and appointments:
- Functions that add and delete appointments/calendars to and from the calendar. Feel free to the design the signatures of theses functions appropriately.
Please be sure to program pure functions (which return a new calendar that represents the addition/deletion).
- (present-calendar-html cal from-time to-time)
A function that presents the appointments of a calendar within a given time interval: From a calendar start time from-time to a calendar end time to-time.
The function must return an HTML value (such as a text string that represents an HTML fragment).
You decide the organization (daily, weekly, monthly, ...) of the resulting calendar.
You are encouraged to isolate concrete HTML details in a specific layer of Scheme functions.
(In other words, try to avoid that HTML details and string concatenations are spread throughout all corners of the function present-calendar-html).
- (find-appointments cal pred)
Find and return the list of all appointments in the calendar cal that fulfills the appointment predicate pred.
- (find-first-appointment cal pred)
Find the earliest appointment (if any) that satisfies the appointment predicate pred.
Return #f if no such appointment exists in the calendar.
- (find-last-appointment cal pred)
As find-first-appointment, but find the latest appointment instead of the earliest.
- (flatten-calendar cal)
A function that eliminates nested calendars. All appointments of nested calendards must be raised to appointments in the top-level calendar.
The function should return the flattened calendar.
- (appointments-overlap? ap1 ap2)
A predicate that returns if the two appointments ap1 and ap2 overlap in time. Please notice that two appointments can be overlapping in several different ways.
- (calendars-overlap? cal1 cal2)
A predicate that returns if two calendars have one or more overlapping appointments.
If this functions returns false (#f), all appointments in the two calendars are temporally disjoint.
In case of inaccuracies in the formulations of this exercise, please state the conditions under which you have created you solution.
There is no solution to this exercise