Range expansion: Difference between revisions

m
(→‎{{header|AppleScript}}: Added idiomatic solution.)
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(lstAccumulatoracc, strNum, iPosn, lstxs)
if strNum ≠ "" then
if iPosn > 1 then
ifset strSign to |λ|(0 < length of (item (iPosn - 1) of lstxs)) > 0 then¬
setof strSign tobool("", "-")
else
set strSign to "-"
end if
else
set strSign to "+"
end if
lstAccumulator & ((strSign & strNum) as integer)
acc & ((strSign & strNum) as integer)
else
lstAccumulatoracc
end if
end signedIntegerAppended
Line 435 ⟶ 436:
 
 
-- TEST --------------------------------------------- TEST --------------------------
on run
Line 444 ⟶ 445:
 
 
-- GENERIC FUNCTIONS -------------------------------------- GENERIC FUNCTIONS --------------------
 
 
-- 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 strSigne to "-"tf
else
set e to ff
end if
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===
 
9,655

edits