Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: optimization?

From: Tom::Conlin::gmail::com at: 28-Sep-2007 23:00

Kai Peters wrote:
> I have a strong feeling that my code below can be significantly > shortened and optimized - any suggestions? > > TIA, > Kai > > Create a block containing the days of the week for an entire month > based on a given date. > > Disregard the missing leapyear handling - none of us will be around to see > it screw up! > > Input: 2007-02-14 > Output: [ "Thu" "Fri" ...... ] > > curdate: 2007-02-14 > ; > days-per-month: [ 31 28 31 30 31 31 30 31 30 31 ] > weekdays: [ "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun" ] > m: curdate/month > maxday: days-per-month/:m > days: copy [] > for day 1 maxday 1 [ tdate: to-date rejoin [ curdate/year "-" > curdate/month "-" day ] > wd: tdate/weekday > wd: weekdays/:wd > append days wd > ] > probe days >
it will miss the leap day in feb when the year is divisible by four but the error does not propagate monthdays: func [ cal [date!] /local month-end weekday result ][ month-end: [30 27 30 29 30 29 30 30 29 30 29 30] weekday: make block! 8 foreach wd system/locale/days[insert tail weekday copy/part wd 3] insert tail weekday first weekday result: make block! 35 cal: to date! reduce[cal/1 cal/2 1] insert/only result weekday/(cal/weekday) loop month-end/(cal/2)[ insert/only tail result select weekday last result ] result ]