Advertisement
zerooneday

ex3_2

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