Find the last Sunday of each month: Difference between revisions
Content added Content deleted
(Added F# version) |
(→{{Header|AppleScript}}: Simpler closures, updated primitives) |
||
Line 98: | Line 98: | ||
-- lastWeekDaysOfYear :: Int -> Int -> [Date] |
-- lastWeekDaysOfYear :: Int -> Int -> [Date] |
||
on lastWeekDaysOfYear(intYear, iWeekday) |
on lastWeekDaysOfYear(intYear, iWeekday) |
||
-- lastWeekDay :: Int -> Int -> Date |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end lastWeekDaysOfYear |
end lastWeekDaysOfYear |
||
-- lastWeekDay :: Int -> Int -> Date |
|||
⚫ | |||
set iYear to intYear of my closure |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Line 156: | Line 155: | ||
-- transpose :: [[a]] -> [[a]] |
-- transpose :: [[a]] -> [[a]] |
||
on transpose( |
on transpose(rows) |
||
script column |
|||
on lambdaCol(_, iCol) |
|||
-- Just the index of each top row item |
|||
on lambda(_, n) |
|||
script nthCell |
|||
on |
on lambda(row) |
||
item n of row |
|||
end |
end lambda |
||
end script |
|||
-- Column n consists of |
|||
-- cell n of each row |
|||
map(nthCell, rows) |
|||
end lambda |
|||
end script |
end script |
||
map(mclosure(mf's lambdaCol, {xss:xss, mf:mf}), item 1 of xss) |
|||
-- A column from each item of the top row |
|||
map(column, item 1 of rows) |
|||
end transpose |
end transpose |
||
Line 222: | Line 229: | ||
end script |
end script |
||
end mReturn |
end mReturn |
||
-- Handler -> Record -> Script |
|||
on mclosure(f, recBindings) |
|||
⚫ | |||
property closure : recBindings |
|||
⚫ | |||
⚫ | |||
end mclosure |
|||
-- cond :: Bool -> (a -> b) -> (a -> b) -> (a -> b) |
-- cond :: Bool -> (a -> b) -> (a -> b) -> (a -> b) |
||
Line 243: | Line 242: | ||
on apply(f, a) |
on apply(f, a) |
||
mReturn(f)'s lambda(a) |
mReturn(f)'s lambda(a) |
||
end apply |
end apply</lang> |
||
</lang> |
|||
{{Out}} |
{{Out}} |