June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,22 +1,21 @@
use framework "Foundation" -- ( for case conversion function )
-- PANGRAM CHECK -------------------------------------------------------------
-- isPangram :: String -> Bool
on isPangram(s)
script charUnUsed
property lowerCaseString : my toLowerCase(s)
on lambda(c)
property lowerCaseString : my toLower(s)
on |λ|(c)
lowerCaseString does not contain c
end lambda
end |λ|
end script
length of filter(charUnUsed, "abcdefghijklmnopqrstuvwxyz") = 0
end isPangram
-- TEST
-- TEST ----------------------------------------------------------------------
on run
map(isPangram, {¬
"is this a pangram", ¬
@ -25,8 +24,7 @@ on run
--> {false, true}
end run
-- GENERIC HIGHER ORDER FUNCTIONS (FILTER AND MAP)
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
@ -35,7 +33,7 @@ on filter(f, xs)
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
if |λ|(v, i, xs) then set end of lst to v
end repeat
return lst
end tell
@ -47,7 +45,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
@ -60,32 +58,14 @@ on mReturn(f)
f
else
script
property lambda : f
property |λ| : f
end script
end if
end mReturn
-- OBJC function: lowercaseStringWithLocale
-- toLowerCase :: String -> String
on toLowerCase(str)
-- toLower :: String -> String
on toLower(str)
set ca to current application
unwrap(wrap(str)'s ¬
lowercaseStringWithLocale:(ca's NSLocale's currentLocale))
end toLowerCase
-- wrap :: AS value -> NSObject
on wrap(v)
set ca to current application
ca's (NSArray's arrayWithObject:v)'s objectAtIndex:0
end wrap
-- unwrap :: NSObject -> AS value
on unwrap(objCValue)
if objCValue is missing value then
return missing value
else
set ca to current application
item 1 of ((ca's NSArray's arrayWithObject:objCValue) as list)
end if
end unwrap
((ca's NSString's stringWithString:(str))'s ¬
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toLower