Reverse words in a string: Difference between revisions

m
→‎{{header|AppleScript}}: Updated primitives
(Added Kotlin)
m (→‎{{header|AppleScript}}: Updated primitives)
Line 214:
=={{header|AppleScript}}==
 
<lang AppleScript>on run {}
 
unlines(map(reverseWords, |lines|("---------- Ice and Fire ------------
Line 226:
Frost Robert -----------------------")))
 
end run
 
 
-- GENERIC FUNCTIONS ---------------------------------------------------------
 
-- reverseWords :: String -> String
Line 281 ⟶ 284:
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
scripttell mfmReturn(f)
propertyset lambdalng :to flength of xs
end script set lst to {}
set lst repeat with i from 1 to {}lng
set lngend of lst to lengthlambda(item i of xs, i, xs)
repeat with i from 1end to lngrepeat
set end ofreturn lst to mf's lambda(item i of xs, i, xs)
end repeattell
end map</lang>
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}}
 
9,659

edits