September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -31,17 +31,17 @@ on expansion(strExpr)
|
|||
end if
|
||||
end signedIntegerAppended
|
||||
|
||||
on lambda(strHyphenated)
|
||||
on |λ|(strHyphenated)
|
||||
tupleRange(foldl(signedIntegerAppended, {}, ¬
|
||||
splitOn("-", strHyphenated)))
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
concatMap(signedRange, splitOn(",", strExpr))
|
||||
end expansion
|
||||
|
||||
|
||||
-- TEST
|
||||
-- TEST -----------------------------------------------------------------------
|
||||
on run
|
||||
|
||||
expansion("-6,-3--1,3-5,7-11,14,15,17-20")
|
||||
|
|
@ -50,27 +50,40 @@ on run
|
|||
end run
|
||||
|
||||
|
||||
|
||||
-- GENERIC LIBRARY FUNCTIONS
|
||||
-- GENERIC FUNCTIONS ----------------------------------------------------------
|
||||
|
||||
-- concatMap :: (a -> [b]) -> [a] -> [b]
|
||||
on concatMap(f, xs)
|
||||
script append
|
||||
on lambda(a, b)
|
||||
on |λ|(a, b)
|
||||
a & b
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
foldl(append, {}, map(f, xs))
|
||||
end concatMap
|
||||
|
||||
-- enumFromTo :: Int -> Int -> [Int]
|
||||
on enumFromTo(m, n)
|
||||
if n < m then
|
||||
set d to -1
|
||||
else
|
||||
set d to 1
|
||||
end if
|
||||
set lst to {}
|
||||
repeat with i from m to n by d
|
||||
set end of lst to i
|
||||
end repeat
|
||||
return lst
|
||||
end enumFromTo
|
||||
|
||||
-- foldl :: (a -> b -> a) -> a -> [b] -> a
|
||||
on foldl(f, startValue, xs)
|
||||
tell mReturn(f)
|
||||
set v to startValue
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to lambda(v, item i of xs, i, xs)
|
||||
set v to |λ|(v, item i of xs, i, xs)
|
||||
end repeat
|
||||
return v
|
||||
end tell
|
||||
|
|
@ -82,7 +95,7 @@ on map(f, xs)
|
|||
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)
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
|
|
@ -95,41 +108,11 @@ on mReturn(f)
|
|||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
-- range :: (Int, Int) -> [Int]
|
||||
on tupleRange(tuple)
|
||||
if tuple = {} then
|
||||
{}
|
||||
else if length of tuple > 1 then
|
||||
range(item 1 of tuple, item 2 of tuple)
|
||||
else
|
||||
item 1 of tuple
|
||||
end if
|
||||
end tupleRange
|
||||
|
||||
-- range :: Int -> Int -> [Int]
|
||||
on range(m, n)
|
||||
set d to cond(n < m, -1, 1)
|
||||
set lst to {}
|
||||
repeat with i from m to n by d
|
||||
set end of lst to i
|
||||
end repeat
|
||||
return lst
|
||||
end range
|
||||
|
||||
-- cond :: Bool -> (a -> b) -> (a -> b) -> (a -> b)
|
||||
on cond(bool, f, g)
|
||||
if bool then
|
||||
f
|
||||
else
|
||||
g
|
||||
end if
|
||||
end cond
|
||||
|
||||
-- splitOn :: Text -> Text -> [Text]
|
||||
on splitOn(strDelim, strMain)
|
||||
set {dlm, my text item delimiters} to {my text item delimiters, strDelim}
|
||||
|
|
@ -137,3 +120,14 @@ on splitOn(strDelim, strMain)
|
|||
set my text item delimiters to dlm
|
||||
return xs
|
||||
end splitOn
|
||||
|
||||
-- range :: (Int, Int) -> [Int]
|
||||
on tupleRange(tuple)
|
||||
if tuple = {} then
|
||||
{}
|
||||
else if length of tuple > 1 then
|
||||
enumFromTo(item 1 of tuple, item 2 of tuple)
|
||||
else
|
||||
item 1 of tuple
|
||||
end if
|
||||
end tupleRange
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue