Day of the week: Difference between revisions
→{{header|AppleScript}}
PatGarrett (talk | contribs) (→{{header|360 Assembly}}: Superfluous blanks suppressed) |
|||
Line 201:
end repeat
ChristmasSundays</lang>
Or, using a higher-order filter function, and a
more functional style of composition:
<lang applescript>on run
filter(xmasIsSunday, range(2008, 2121))
end run
-- xmasIsSunday :: Int -> Bool
on xmasIsSunday(y)
tell (current date)
set {its year, its month, its day, its time} to {y, 12, 25, 0}
return its weekday is Sunday
end tell
end xmasIsSunday
-- GENERIC FUNCTIONS
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
script mf
property lambda : f
end script
set lst to {}
set lng to length of xs
repeat with i from 1 to lng
set v to item i of xs
if mf's lambda(v, i, xs) then
set end of lst to v
end if
end repeat
return lst
end filter
-- range :: Int -> Int -> [Int]
on range(m, n)
set lng to (n - m) + 1
set base to m - 1
set lst to {}
repeat with i from 1 to lng
set end of lst to i + base
end repeat
return lst
end range</lang>
{{Out}}
<pre>{2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067,
2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118}</pre>
=={{header|AutoHotkey}}==
|