Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,14 @@
set L to {3, 2, 1, 0, -1, -2, -3}
set evens to {}
set odds to {}
repeat with x in L
if (x mod 2 = 0) then
set the end of evens to x's contents
else
set the end of odds to x's contents
end if
end repeat
return {even:evens, odd:odds}

View file

@ -0,0 +1 @@
{even:{2, 0, -2}, odd:{3, 1, -1, -3}}

View file

@ -0,0 +1,67 @@
----------------------- EVEN OR ODD ------------------------
-- even :: Int -> Bool
on even(n)
0 = n mod 2
end even
-- odd :: Int -> Bool
on odd(n)
not even(n)
end odd
--------------------------- TEST ---------------------------
on run
partition(odd, enumFromTo(-6, 6))
--> {{-5, -3, -1, 1, 3, 5}, {-6, -4, -2, 0, 2, 4, 6}}
end run
-------------------- GENERICS FOR TEST ---------------------
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
if m n then
set lst to {}
repeat with i from m to n
set end of lst to i
end repeat
lst
else
{}
end if
end enumFromTo
-- partition :: (a -> Bool) -> [a] -> ([a], [a])
on partition(p, xs)
tell mReturn(p)
set {ys, zs} to {{}, {}}
repeat with x in xs
set v to contents of x
if |λ|(v) then
set end of ys to v
else
set end of zs to v
end if
end repeat
end tell
{ys, zs}
end partition
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
on mReturn(f)
-- 2nd class handler function lifted into 1st class script wrapper.
if script is class of f then
f
else
script
property |λ| : f
end script
end if
end mReturn

View file

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