Day of the week: Difference between revisions

Line 207:
more functional style of composition:
 
<lang applescript>on-- runxmasIsSunday :: Int -> Bool
filter(xmasIsSunday, range(2008, 2121))
end run
 
 
-- xmasIsSunday :: Int -> Bool
on xmasIsSunday(y)
tell (current date)
Line 224 ⟶ 217:
 
 
-- TEST ------------------------------------------------------------------
-- GENERIC FUNCTIONS
on run
filter(xmasIsSunday, range(2008, 2121))
end run
 
 
 
-- GENERIC FUNCTIONS -----------------------------------------------------
 
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
scripttell mfmReturn(f)
propertyset lambdalst :to f{}
set lng to length of xs
end script
repeat with i from 1 to lng
set lstv to {}item i of xs
if lambda(v, i, xs) then set end of lst to v
set lng to length of xs
repeat with i from 1end to lngrepeat
setreturn v to item i of xslst
end tell
if mf's lambda(v, i, xs) then
set end of lst to v
end if
end repeat
return lst
end filter
 
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
end script
property lambda : f
end script
end if
end mReturn
 
-- range :: Int -> Int -> [Int]
on range(m, n)
setif lng to (n -< m) + 1then
set based to m - 1
else
set d to 1
end if
set lst to {}
repeat with i from 1m to lngn by d
set end of lst to i + base
end repeat
return lst
Line 255 ⟶ 268:
 
{{Out}}
<prelang AppleScript>{2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067,
2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118}</prelang>
 
=={{header|AutoHotkey}}==
9,659

edits