September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,8 @@
set nList to {3, 2, 1, 0, -1, -2, -3}
repeat with n in nList
if (n / 2) = n / 2 as integer then
log "Value " & n & " is even."
else
log "Value " & n & " is odd."
end if
end repeat

View file

@ -0,0 +1,45 @@
-- even :: Integral a => a -> Bool
on even(n)
n mod 2 = 0
end even
-- odd :: Integral a => a -> Bool
on odd(n)
not even(n)
end odd
-- GENERIC FUNCTIONS FOR TEST ----------------------------------
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
tell mReturn(f)
set lst to {}
set lng to length of xs
repeat with i from 1 to lng
set v to item i of xs
if lambda(v, i, xs) then set end of lst to v
end repeat
return lst
end tell
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
script
property lambda : f
end script
end if
end mReturn
-- TEST ---------------------------------------------------------
on run
set xs to [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
{filter(even, xs), filter(odd, xs)}
end run

View file

@ -0,0 +1 @@
{{-6, -4, -2, 0, 2, 4, 6}, {-5, -3, -1, 1, 3, 5}}

View file

@ -1,8 +0,0 @@
set nList to {3, 2, 1, 0, -1, -2, -3}
repeat with n in nList
if (n / 2) = n / 2 as integer then
log "Value " & n & " is even."
else
log "Value " & n & " is odd."
end if
end repeat