Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,77 @@
|
|||
use framework "Foundation" -- ( for case conversion function )
|
||||
|
||||
--------------------- PANGRAM CHECKER --------------------
|
||||
|
||||
-- isPangram :: String -> Bool
|
||||
on isPangram(s)
|
||||
script charUnUsed
|
||||
property lowerCaseString : my toLower(s)
|
||||
on |λ|(c)
|
||||
lowerCaseString does not contain c
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
0 = length of filter(charUnUsed, ¬
|
||||
"abcdefghijklmnopqrstuvwxyz")
|
||||
end isPangram
|
||||
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
on run
|
||||
map(isPangram, {¬
|
||||
"is this a pangram", ¬
|
||||
"The quick brown fox jumps over the lazy dog"})
|
||||
|
||||
--> {false, true}
|
||||
end run
|
||||
|
||||
|
||||
-------------------- GENERIC FUNCTIONS -------------------
|
||||
|
||||
-- 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
|
||||
|
||||
|
||||
-- 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 |λ|(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 |λ| : 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
|
||||
|
|
@ -0,0 +1 @@
|
|||
{false, true}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
on isPangram(txt)
|
||||
set alphabet to "abcedfghijklmnopqrstuvwxyz"
|
||||
ignoring case -- The default, but ensure it here.
|
||||
repeat with letter in alphabet
|
||||
if (txt does not contain letter) then return false
|
||||
end repeat
|
||||
end ignoring
|
||||
|
||||
return true
|
||||
end isPangram
|
||||
|
||||
local result1, result2
|
||||
set result1 to isPangram("The Quick Brown Fox Jumps Over The Lazy Dog")
|
||||
set result2 to isPangram("This is not a pangram")
|
||||
return {result1, result2}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{true, false}
|
||||
Loading…
Add table
Add a link
Reference in a new issue