### Rules to create a 365-day calendar and set the proper ### train schedule for July 4. Operator version. max-elaborations 5000 sp {initialize*calendar (state ^superstate nil) --> ( ^year ) ( ^value 2003)} sp {initialize*months (state ^year ) --> ( ^month.name january) ( ^month.name february) ( ^month.name march) ( ^month.name april) ( ^month.name may) ( ^month.name june) ( ^month.name july) ( ^month.name august) ( ^month.name september) ( ^month.name october) ( ^month.name november) ( ^month.name december)} sp {initialize*31day*length (state ^year.month ) ( ^name << january march may july august october december >> ) --> ( ^days 31)} sp {initialize*30day*length (state ^year.month ) ( ^name << september april june november >> ) --> ( ^days 30)} sp {initialize*february*length (state ^year.month ) ( ^name february) --> ( ^days 28)} sp {initialize*first*days (state ^year.month ) --> ( ^day ) ( ^date 1)} sp {initialize*remaining*days (state ^year.month ) ( ^days ) ( ^day.date {
< } ) --> ( ^day ) ( ^date ( +
1 ))} sp {initialize*newyearsday (state ^year ) ( ^value 2003) ( ^month ) ( ^name january) ( ^day ) ( ^date 1) --> ( ^dayofweek wednesday)} sp {elaborate*daysofweek*onemonth (state ^year.month ) ( ^day ) ( ^day ) ( ^date
^dayofweek ) ( ^date { >
} ) - ( ^date { >
< } ) ( ^nextday ) ( ^day ^next ) --> ( ^dayofweek )} sp {elaborate*daysofweek*startnewmonth (state ^year.month ) ( ^name ) (state ^year.month ) ( ^name { <> january } ) ( ^nextmonth ) ( ^month ^next ) ( ^days ^day ) ( ^date ^dayofweek ) ( ^days ^day ) ( ^date 1) ( ^nextday ) ( ^day ^next ) --> ( ^dayofweek )} sp {holiday*july4th (state ^year.month ) ( ^name july) ( ^day ) ( ^date 4) --> ( ^holiday true)} sp {initialize*orderofdays (state ^superstate nil) --> ( ^nextday ) ( ^day monday ^next tuesday) ( ^nextday ) ( ^day tuesday ^next wednesday) ( ^nextday ) ( ^day wednesday ^next thursday) ( ^nextday ) ( ^day thursday ^next friday) ( ^nextday ) ( ^day friday ^next saturday) ( ^nextday ) ( ^day saturday ^next sunday) ( ^nextday ) ( ^day sunday ^next monday)} sp {initialize*orderofmonths (state ^superstate nil) --> ( ^nextmonth ) ( ^month january ^next february) ( ^nextmonth ) ( ^month february ^next march) ( ^nextmonth ) ( ^month march ^next april) ( ^nextmonth ) ( ^month april ^next may) ( ^nextmonth ) ( ^month may ^next june) ( ^nextmonth ) ( ^month june ^next july) ( ^nextmonth ) ( ^month july ^next august) ( ^nextmonth ) ( ^month august ^next september) ( ^nextmonth ) ( ^month september ^next october) ( ^nextmonth ) ( ^month october ^next november) ( ^nextmonth ) ( ^month november ^next december) ( ^nextmonth ) ( ^month december ^next january)} ### Three rules to propose, apply and remove the operator ### schedule-friday-trains sp {propose*schedule*fridaytrains (state ^year.month.day ) ( ^dayofweek friday) --> ( ^operator + =) ( ^name schedule-friday-trains ^day )} sp {apply*schedule*fridaytrains (state ^year.month.day ^operator ) ( ^name schedule-friday-trains ^day ) --> ( ^trains 9am 11am 1pm 3pm 5pm 7pm) (write (crlf) |July 4th trains| (crlf) ) (write (crlf) 9am 11am 1pm 3pm 5pm 7pm (crlf) ) ( ^completed yes)} sp {apply*schedule*remove-schedulefriday (state ^year.month.day ^operator ) ( ^name schedule-friday-trains ^day ^completed yes) --> ( ^operator -)} ### Three rules to propose, apply and remove the operator ### schedule-holiday-trains sp {propose*schedule*holidaytrains (state ^year.month.day ) ( ^holiday true) --> ( ^operator + > =) ( ^name schedule-holiday-trains ^day )} sp {apply*schedule*holidaytrains (state ^year.month.day ^operator ) ( ^name schedule-holiday-trains ^day ) --> ( ^trains 10am 2pm 6pm) (write (crlf) |July 4th trains| (crlf) ) (write (crlf) 10am (crlf) 2pm (crlf) 6pm (crlf) ) ( ^completed yes)} sp {apply*schedule*remove-scheduleholiday (state ^year.month.day ^operator ) ( ^name schedule-holiday-trains ^day ^completed yes) --> ( ^operator -)} sp {stop*soar (state ^year.month ) ( ^day ^name july) ( ^date 4 ^trains ) --> (halt)}