Testing parametric code with print statements

18 views
Skip to first unread message

Brandon Barker

unread,
Jan 14, 2014, 3:39:01 PM1/14/14
to ats-lan...@googlegroups.com
Say you want to inspect the implementation of some parametric code dynamically by printing data on test cases. print() does not work for any t@ype, so it would be nice to assert:

a is printable
a = a specific type .

So as to not "dumb down" the implementation by removing the parameterization.

I tried to do this with a praxi but failed.

Or, is there some other alternative?

gmhwxi

unread,
Jan 14, 2014, 3:50:18 PM1/14/14
to ats-lan...@googlegroups.com
You can use 'print_val<a> (...)' or fprint_val<a> (...)'.

Brandon Barker

unread,
Jan 14, 2014, 4:23:13 PM1/14/14
to ats-lan...@googlegroups.com
Great, I implemented it in ATS1 like this, and show how to use it to print a list_vt:

extern
fun{a:t0p} print_val(x: a): void

implement
print_val<int> (x) = print(x)

fun{a:t0p} print_lvt(xsl: !List_vt (a)): void =
begin (
list_vt_foreach_fun<a> (xsl, lam x =<1> (print_val<a> (x); print ' '));
print_newline();
) end

In ATS2, this relies on the function 'tostrptr_val'. Perhaps I am just failing with my greps, but would it be useful if I implemented this for some of the common types (int, double, char, strings, etc)?

gmhwxi

unread,
Jan 14, 2014, 4:30:25 PM1/14/14
to ats-lan...@googlegroups.com
These have already been implemented:

val () = print_val<int> (0)
val () = print_val<string> ("0")
val () = print_val<double> (0.0)

To print out a list, you can use fprint_list or fprint_list_sep.


On Tuesday, January 14, 2014 3:39:01 PM UTC-5, Brandon Barker wrote:
Reply all
Reply to author
Forward
0 new messages