This one works:
fun{a:vt0p}
print_arr (arr: !arrayptr (INV(a), N)):void = {
implement array_foreach$fwork (x, env) = print x
val _ = arrayptr_foreach (arr, i2sz N)
}
However, this is not a good style. Try:
fun{a:vt0p}
print_arr (arr: !arrayptr (INV(a), N)):void = {
implement array_foreach$fwork (x, env) = fprint_ref (
stdout_ref, x)
val _ = arrayptr_foreach (arr, i2sz N)
}On Friday, July 24, 2015 at 4:01:16 AM UTC-4, Kiwamu Okabe wrote:
Hi all,
How to use template function on arrayptr?
I’m writing code to print entries in arrayptr.
https://github.com/jats-ug/practice-ats/blob/7ccf4286f38121a133040348f138a9bf622338bc/array_v_mergesort/main.dats
fun{a:viewt@ype} print_arr (arr: !arrayptr (INV(a), N)):void = { implement array_foreach$fwork<int><int> (x, env) = env := (print x; 0) val _ = arrayptr_foreach (arr, i2sz N) } implement main0 () = { val arr = arr_takeout () val () = print_arr arr val () = arr_addback (arr) }
However the code has error at C language side.
$ patscc main.dats In file included from main_dats.c:15:0: main_dats.c: In function ‘loop_11__11__1’: main_dats.c:1272:27: error: ‘PMVtmpltcstmat’ undeclared (first use in this function) ATSINSmove_void(tmp24__1, PMVtmpltcstmat[0](array_foreach$fwork<S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))><S2Ecst(atsvoid_t0ype)>)(ATSPMVrefarg1(arg0), ATSPMVrefarg1(arg2))) ; ^
Best regards,
Kiwamu Okabe at METASEPI DESIGN