Jump to content

Find the last Sunday of each month: Difference between revisions

→‎{{Header|AppleScript}}: Simpler closures, updated primitives
(Added F# version)
(→‎{{Header|AppleScript}}: Simpler closures, updated primitives)
Line 98:
-- lastWeekDaysOfYear :: Int -> Int -> [Date]
on lastWeekDaysOfYear(intYear, iWeekday)
map(mclosure(my-- lastWeekDay, ¬:: Int -> Int -> Date
end script lastWeekDay
{intYear:intYear, iWeekday:iWeekday}), my lastDaysOfMonths(intYear))
on lastWeekDaylambda(iLastDay, iMonth)
property lambda : f
calendarDate(iYearintYear, iMonth, iLastDay - ¬
(((weekday of calendarDate(iYearintYear, iMonth, iLastDay)) as integer) + ¬
(7 - (iWeekday of my closure))) mod 7)
end scriptlambda
end script
{intYear:intYear, iWeekday:iWeekday})map(lastWeekDay, my lastDaysOfMonths(intYear))
end lastWeekDaysOfYear
 
 
-- lastWeekDay :: Int -> Int -> Date
on lastWeekDay(iLastDay, iMonth)
set iYear to intYear of my closure
calendarDate(iYear, iMonth, iLastDay - ¬
(((weekday of calendarDate(iYear, iMonth, iLastDay)) as integer) + ¬
(7 - (iWeekday of my closure))) mod 7)
end lastWeekDay
 
 
Line 156 ⟶ 155:
 
-- transpose :: [[a]] -> [[a]]
on transpose(xssrows)
script mf
script column
on lambdaCol(_, iCol)
-- Just the index map(mclosure(myof closure'seach mf'stop lambdaRow,row ¬item
on {iCol:iCol})lambda(_, my closure's xssn)
end lambdaCol
script nthCell
on lambdaRowlambda(row)
item (my closure's iCol) item n of row
end lambdaRowlambda
end script
-- Column n consists of
-- cell n of each row
map(nthCell, rows)
end lambda
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
 
Line 222 ⟶ 229:
end script
end mReturn
 
-- Handler -> Record -> Script
on mclosure(f, recBindings)
script
property closure : recBindings
property lambda : f
end script
end mclosure
 
-- cond :: Bool -> (a -> b) -> (a -> b) -> (a -> b)
Line 243 ⟶ 242:
on apply(f, a)
mReturn(f)'s lambda(a)
end apply</lang>
</lang>
 
{{Out}}
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.