Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. (*
  2. ** CS-520 assignment0
  3. ** assign00_3_2.dats
  4. *)
  5.  
  6. (* ****** ****** *)
  7.  
  8. #define
  9. LIBATSCC2JS_targetloc
  10. "contrib/libatscc2js/ATS2-0.3.2"
  11.  
  12. (* ****** ****** *)
  13.  
  14. #include
  15. "{$LIBATSCC2JS}/staloadall.hats"
  16.  
  17. (* ****** ****** *)
  18.  
  19. staload
  20. "{$LIBATSCC2JS}/SATS/print.sats"
  21.  
  22. (* ****** ****** *)
  23.  
  24. #define ATS_MAINATSFLAG 1
  25. #define ATS_DYNLOADNAME "my_dynload"
  26.  
  27. (* ****** ****** *)
  28. //
  29.  
  30. extern fun count_ones(n: int): int
  31.  
  32. implement count_ones(n) =
  33. let
  34. // pyhsieh: Helper function for tail-recursion
  35. fun aux(quo: int, res: int): int =
  36. if quo = 0
  37. then res
  38. else aux(quo / 2, res + (quo % 2))
  39. in
  40. aux(n, 0)
  41. end
  42. //
  43. (* ****** ****** *)
  44. //
  45. val N = 100
  46. //
  47. val () = println! ("count_ones(", N, ") = ", count_ones(N))
  48. //
  49. (* ****** ****** *)
  50.  
  51. %{$
  52. //
  53. ats2jspre_the_print_store_clear();
  54. my_dynload();
  55. alert(ats2jspre_the_print_store_join());
  56. //
  57. %} // end of [%{$]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement