2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,21 @@
on run
transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
--> {{1, 4, 7, 10}, {2, 5, 8, 11}, {3, 6, 9, 12}}
end run
on transpose(xss)
set lstTrans to {}
repeat with iCol from 1 to length of item 1 of xss
set lstCol to {}
repeat with iRow from 1 to length of xss
set end of lstCol to item iCol of item iRow of xss
end repeat
set end of lstTrans to lstCol
end repeat
return lstTrans
end transpose

View file

@ -0,0 +1,52 @@
-- transpose :: [[a]] -> [[a]]
on transpose(xss)
script column
on lambda(_, iCol)
script row
on lambda(xs)
item iCol of xs
end lambda
end script
map(row, xss)
end lambda
end script
map(column, item 1 of xss)
end transpose
-- TEST
on run
transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
--> {{1, 4, 7, 10}, {2, 5, 8, 11}, {3, 6, 9, 12}}
end run
-- GENERIC LIBRARY FUNCTIONS
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to lambda(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- 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

View file

@ -0,0 +1 @@
{{1, 4, 7, 10}, {2, 5, 8, 11}, {3, 6, 9, 12}}