Find the last Sunday of each month: Difference between revisions
→AppleScript
Line 48:
<lang AppleScript>on run argv
-- Default range in absence of arguments: from two years ago, to two years ahead
-- Up to two optional command line arguments: [yearFrom], [yearTo]
-- ~ $ osascript ~/Desktop/lastSundays.scpt
--
-- ~ $ osascript ~/Desktop/lastSundays.scpt 2013
--
-- ~ $ osascript ~/Desktop/lastSundays.scpt 2013 2016
set intThisYear to year of (current date)
if class of argv is list then
set lngArgs to length of argv
if lngArgs > 0 then
if lngArgs > 1 then
set {intFrom, intTo} to argv
set intYear to item 1 of argv
set {intFrom, intTo} to {intYear, intYear}
else
set {intFrom, intTo} to {intThisYear - 2, intThisYear + 2}
else
set {intFrom, intTo} to {intThisYear - 2, intThisYear + 2}
end if
intercalate(linefeed, ¬
map(isoRow, ¬
transpose(map(lastSundaysOfYear, range(
end run
-- DERIVATION OF LAST
-- lastSundaysOfYear :: Int -> [Date]
Line 91 ⟶ 119:
{31, iFeb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
end lastDaysOfMonths
-- GENERIC FUNCTIONS
Line 116 ⟶ 145:
-- Testing and tabulation
--
on
script mf▼
intercalate(tab, map(my isoDateString, lstDate))▼
on lambdaCol(_, iCol)▼
end isoRow▼
map(mClosure(my closure's mf's lambdaRow, ¬▼
{iCol:iCol}), my closure's xss)▼
end lambdaCol
on lambdaRow(row)▼
item (my closure's iCol) of row▼
end lambdaRow
end script
map(mClosure(mf's lambdaCol, {xss:xss, mf:mf}), item 1 of xss)▼
end transpose▼
-- intercalate :: Text -> [Text] -> Text
Line 129 ⟶ 168:
return strJoined
end intercalate
on isoRow(lstDate)
▲ intercalate(tab, map(my isoDateString, lstDate))
▲end isoRow
-- range :: Int -> Int -> [Int]
Line 140 ⟶ 184:
return lst
end range
▲-- transpose :: [[a]] -> [[a]]
▲ script mf
▲ on lambdaCol(_, iCol)
▲ map(mClosure(my closure's mf's lambdaRow, ¬
▲ {iCol:iCol}), my closure's xss)
▲ end lambdaCol
▲ on lambdaRow(row)
▲ item (my closure's iCol) of row
▲ end lambdaRow
▲ end script
▲ map(mClosure(mf's lambdaCol, {xss:xss, mf:mf}), item 1 of xss)
▲end transpose
Line 169 ⟶ 198:
return lst
end map
-- Lift 2nd class handler function into 1st class script wrapper
Line 190 ⟶ 217:
{{Out}}
<pre>
=={{header|AutoHotkey}}==
|