Pangram checker: Difference between revisions

Content added Content deleted
(Added FreeBASIC)
m (→‎{{header|AppleScript}}: Updated primitives)
Line 215: Line 215:
-- GENERIC HIGHER ORDER FUNCTIONS (FILTER AND MAP)
-- GENERIC HIGHER ORDER FUNCTIONS (FILTER AND MAP)


-- (a -> Bool) -> [a] -> [a]
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
on filter(f, xs)
set mf to mReturn(f)
tell mReturn(f)
set lst to {}
set lst to {}
set lng to length of xs
repeat with i from 1 to lng
set lng to length of xs
repeat with i from 1 to lng
set v to item i of xs
set v to item i of xs
if lambda(v, i, xs) then set end of lst to v
if mf's lambda(v, i, xs) then
end repeat
set end of lst to v
return lst
end if
end tell
end repeat
return lst
end filter
end filter


-- map :: (a -> b) -> [a] -> [b]
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
on map(f, xs)
set mf to mReturn(f)
tell mReturn(f)
set lng to length of xs
set lng to length of xs
set lst to {}
set lst to {}
repeat with i from 1 to lng
repeat with i from 1 to lng
set end of lst to mf's lambda(item i of xs, i, xs)
set end of lst to lambda(item i of xs, i, xs)
end repeat
end repeat
return lst
return lst
end tell
end map
end map


-- Lift 2nd class function into 1st class wrapper
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
-- handler function --> first class script object
on mReturn(f)
on mReturn(f)
if class of f is script then return f
if class of f is script then
script
f
else
property lambda : f
end script
script
property lambda : f
end script
end if
end mReturn
end mReturn


Line 274: Line 276:
end if
end if
end unwrap
end unwrap

</lang>
</lang>