Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/4d4e407a6ae2b7d419b3 to your computer and use it in GitHub Desktop.
Save rightfold/4d4e407a6ae2b7d419b3 to your computer and use it in GitHub Desktop.
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