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

@ -1,43 +1,48 @@
use framework "Foundation"
-- CASE-INSENSITIVE PALINDROME, IGNORING SPACES ? ----------------------------
-- isPalindrome :: String -> Bool
on isPalindrome(s)
s = intercalate("", reverse of characters of s)
end isPalindrome
-- toSpaceFreeLower :: String -> String
on spaceFreeToLower(s)
script notSpace
on |λ|(s)
s is not space
end |λ|
end script
intercalate("", filter(notSpace, characters of toLower(s)))
end spaceFreeToLower
-- TEST
-- TEST ----------------------------------------------------------------------
on run
isPalindrome(lowerCaseNoSpace("In girum imus nocte et consumimur igni"))
isPalindrome(spaceFreeToLower("In girum imus nocte et consumimur igni"))
--> true
end run
-- lowerCaseNoSpace :: String -> String
on lowerCaseNoSpace(s)
script notSpace
on lambda(s)
s is not space
end lambda
end script
intercalate("", filter(notSpace, characters of toLowerCase(s)))
end lowerCaseNoSpace
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- GENERIC LIBRARY FUNCTIONS
-- toLowerCase :: String -> String
on toLowerCase(str)
set ca to current application
((ca's NSString's stringWithString:(str))'s ¬
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toLowerCase
-- 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 |λ|(v, i, xs) then set end of lst to v
end repeat
return lst
end tell
end filter
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
@ -47,19 +52,6 @@ on intercalate(strText, lstText)
return strJoined
end intercalate
-- 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)
@ -67,7 +59,14 @@ on mReturn(f)
f
else
script
property lambda : f
property |λ| : f
end script
end if
end mReturn
-- toLower :: String -> String
on toLower(str)
set ca to current application
((ca's NSString's stringWithString:(str))'s ¬
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toLower