Repeat a string: Difference between revisions

(Add Egison sample)
Line 94:
print repeat( "ha", 5 )
}</lang>
 
=={{header|ATS}}==
<lang ATS>
//
// How to compile:
// patscc -DATS_MEMALLOC_LIBC -o string_repeat string_repeat.dats
//
 
#include
"share/atspre_staload.hats"
 
fun
string_repeat
(
x: string, n: intGte(0)
) : Strptr1 = res where
{
val xs = list_make_elt<string>(n, x)
val res = stringlst_concat($UNSAFE.list_vt2t(xs))
val () = list_vt_free(xs)
} (* end of [string_repeat] *)
 
(* ****** ****** *)
 
implement
main0 () = let
//
val ha5 = string_repeat("ha", 5)
val ((*void*)) = println! ("ha5 = \"", ha5, "\"")
val ((*freed*)) = strptr_free (ha5)
//
in
// nothing
end // end of [main0]
</lang>
 
=={{header|Babel}}==
Anonymous user