Range expansion: Difference between revisions
m
→AppleScript :: Functional: Tidied.
(→{{header|AppleScript}}: Added idiomatic solution.) |
m (→AppleScript :: Functional: Tidied.) |
||
Line 394:
<lang AppleScript>-- Each comma-delimited string is mapped to a list of integers,
-- and these integer lists are concatenated together into a single list
---------------------- RANGE EXPANSION ---------------------
-- expansion :: String -> [Int]
Line 408 ⟶ 411:
-- signedIntegerAppended:: [Int] -> String -> Int -> [Int] -> [Int]
on signedIntegerAppended(
if strNum ≠ "" then
if iPosn > 1 then
else▼
set strSign to "-"▼
end if▼
else
set strSign to "+"
end if
acc & ((strSign & strNum) as integer)
else
end if
end signedIntegerAppended
Line 435 ⟶ 436:
on run
Line 444 ⟶ 445:
-- bool :: a -> a -> Bool -> a
on bool(tf, ff)
-- The evaluation of either tf or ff,
-- depending on a boolean value.
script
on |λ|(bln)
if bln then
set e to ff
set c to class of e
if {script, handler} contains c then
|λ|() of mReturn(e)
else
e
end if
end |λ|
end script
end bool
-- concatMap :: (a -> [b]) -> [a] -> [b]
Line 528 ⟶ 551:
<lang AppleScript>{-6, -3, -2, -1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20}</lang>
----
===Idiomatic===
|