Phrase reversals: Difference between revisions
m
→{{header|AppleScript}}: (minor reordering)
(Added Kotlin) |
m (→{{header|AppleScript}}: (minor reordering)) |
||
Line 188:
Here is a simple illustration of unifying (and elevating) the function type by wrapping the built-in functions in user handlers (perhaps making some of them polymorphic where needed), and also obtaining first class status for ordinary user handler functions by 'lifting' them (for use as arguments in higher order functions) into a first class script object. (This process can be inlined, or abstracted out to an '''mReturn''' or '''mInject''' function).
<lang AppleScript>
on _reverse(xs)▼
if class of xs is text then▼
(reverse of characters of xs) as text▼
▲ else
reverse of xs▼
end if▼
end _reverse▼
set phrase to "rosetta code phrase reversal"
Line 207 ⟶ 196:
unwords(map(_reverse, _words(phrase))), ¬
unwords(_reverse(_words(phrase)))})
end run
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- _reverse :: [a] -> [a]
▲on _reverse(xs)
▲ if class of xs is text then
▲ (reverse of characters of xs) as text
else
▲ reverse of xs
▲ end if
▲end _reverse
-- map :: (a -> b) -> [a] -> [b]
|