Reverse words in a string: Difference between revisions

Content added Content deleted
(Added Kotlin)
m (→‎{{header|AppleScript}}: Updated primitives)
Line 214: Line 214:
=={{header|AppleScript}}==
=={{header|AppleScript}}==


<lang AppleScript>on run {}
<lang AppleScript>on run

unlines(map(reverseWords, |lines|("---------- Ice and Fire ------------
unlines(map(reverseWords, |lines|("---------- Ice and Fire ------------
Line 226: Line 226:
Frost Robert -----------------------")))
Frost Robert -----------------------")))

end run
end run


-- GENERIC FUNCTIONS ---------------------------------------------------------


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

end map</lang>
-- 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 lambda : f
end script
end if
end mReturn
</lang>
{{out}}
{{out}}