Phrase reversals: Difference between revisions
m
→{{header|AppleScript}}
(→{{header|AppleScript}}: Updated primitives) |
|||
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>
-- _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▼
-- TEST
on run {}
set phrase to "rosetta code phrase reversal"
Line 219 ⟶ 232:
return strJoined
end intercalate
▲-- _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
-- _words :: String -> [String]
Line 255 ⟶ 259:
end if
end mReturn
</lang>
|