Rep-string: Difference between revisions

Content added Content deleted
(Crystal code)
m (→‎{{header|AppleScript}}: Minor tidying)
Line 172: Line 172:


=={{header|AppleScript}}==
=={{header|AppleScript}}==
<lang AppleScript>-- REP-CYCLES ----------------------------------------------------------------
<lang AppleScript>------------------------REP-CYCLES-------------------------


-- repCycles :: String -> [String]
-- repCycles :: String -> [String]
Line 199: Line 199:




-- TEST ----------------------------------------------------------------------
---------------------------TEST----------------------------
on run
on run
set samples to {"1001110011", "1110111011", "0010010010", ¬
set samples to {"1001110011", "1110111011", "0010010010", ¬
Line 206: Line 206:
unlines(cons("Longest cycle:" & linefeed, ¬
unlines(cons("Longest cycle:" & linefeed, ¬
map(curry(intercalate)'s |λ|(" -> "), ¬
map(intercalate(" -> "), ¬
map(cycleReport, samples))))
map(cycleReport, samples))))
Line 212: Line 212:




-- GENERIC FUNCTIONS ---------------------------------------------------------
---------------------GENERIC FUNCTIONS---------------------


-- concat :: [[a]] -> [a] | [String] -> String
-- concat :: [[a]] -> [a] | [String] -> String
Line 231: Line 231:
{x} & xs
{x} & xs
end cons
end cons

-- curry :: (Script|Handler) -> Script
on curry(f)
script
on |λ|(a)
script
on |λ|(b)
|λ|(a, b) of mReturn(f)
end |λ|
end script
end |λ|
end script
end curry


-- filter :: (a -> Bool) -> [a] -> [a]
-- filter :: (a -> Bool) -> [a] -> [a]
Line 293: Line 280:


-- intercalate :: Text -> [Text] -> Text
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
on intercalate(strText)
script
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
on |λ|(xs)
set my text item delimiters to dlm
set {dlm, my text item delimiters} to {my text item delimiters, strText}
return strJoined
set strJoined to xs as text
set my text item delimiters to dlm
return strJoined
end |λ|
end script
end intercalate
end intercalate


Line 410: Line 401:
-- unlines :: [String] -> String
-- unlines :: [String] -> String
on unlines(xs)
on unlines(xs)
intercalate(linefeed, xs)
|λ|(xs) of intercalate(linefeed)
end unlines</lang>
end unlines</lang>
{{Out}}
{{Out}}