-
-
Save rightfold/4d4e407a6ae2b7d419b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func snd(x: Any, y: Any): typeof(y) | |
ensure out is y | |
throw None | |
{ | |
y | |
} | |
func repeat(x: Any, n: Int): Seq | |
ensure count(out) == n | |
{ | |
1..n *> snd(x) | |
} | |
func join(ss: Seq, sep: String = ""): String { | |
if empty?(ss) { "" } else { reduce(ss, (~ sep ~)) } | |
} | |
func repeat-string(s: String, n: Int): String { | |
s ~:repeat:~ n |> join() | |
} | |
MAIN { | |
if count(%argv) != 3 { | |
errln([|usage: #{%argv(0)} string count|]) | |
exit(1) | |
} | |
outln(repeat-string(%argv(1), atoi(%argv(2)))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment