Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- ** CS-520 assignment0
- ** assign00_3_2.dats
- *)
- (* ****** ****** *)
- #define
- LIBATSCC2JS_targetloc
- "contrib/libatscc2js/ATS2-0.3.2"
- (* ****** ****** *)
- #include
- "{$LIBATSCC2JS}/staloadall.hats"
- (* ****** ****** *)
- staload
- "{$LIBATSCC2JS}/SATS/print.sats"
- (* ****** ****** *)
- #define ATS_MAINATSFLAG 1
- #define ATS_DYNLOADNAME "my_dynload"
- (* ****** ****** *)
- //
- extern fun count_ones(n: int): int
- implement count_ones(n) =
- let
- // pyhsieh: Helper function for tail-recursion
- fun aux(quo: int, res: int): int =
- if quo = 0
- then res
- else aux(quo / 2, res + (quo % 2))
- in
- aux(n, 0)
- end
- //
- (* ****** ****** *)
- //
- val N = 100
- //
- val () = println! ("count_ones(", N, ") = ", count_ones(N))
- //
- (* ****** ****** *)
- %{$
- //
- ats2jspre_the_print_store_clear();
- my_dynload();
- alert(ats2jspre_the_print_store_join());
- //
- %} // end of [%{$]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement