home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / SML90.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  2.3 KB  |  77 lines  |  [TEXT/R*ch]

  1. (* Old.sml 1995-02-24, 1996-04-09 -- compatibility with the Definition *)
  2.  
  3. fun (g o f) x = g (f x);
  4. fun a before (b : unit) = a;
  5.  
  6. (* The definitions below implement the requirement that units
  7.    Char, String and List are partially opened in the initial environment.
  8.  *)
  9.  
  10. prim_val chr : int    -> string = 1 "sml_chr";
  11. prim_val ord : string -> int    = 1 "sml_ord";
  12.  
  13. local 
  14.     prim_val create_string_ : int -> string                = 1 "create_string";
  15.     prim_val nth_char_      : string -> int -> int         = 2 "get_nth_char";
  16.     prim_val set_nth_char_  : string -> int -> int -> unit = 3 "set_nth_char";
  17.     prim_val blit_string_   : string -> int -> string -> int -> int -> unit 
  18.                                                            = 5 "blit_string";
  19.  
  20.     open String
  21. in 
  22.     fun explode s =
  23.     let fun loop 0 acc = acc
  24.           | loop n acc =
  25.         let val n' = n - 1
  26.             val x = create_string_ 1
  27.         in
  28.             set_nth_char_ x 0 (nth_char_ s n');
  29.             loop n' (x::acc)
  30.         end
  31.     in loop (size s) [] end;
  32.  
  33.     fun implode ss =
  34.     let fun resultSizeAcc [] acc = acc
  35.           | resultSizeAcc (s::ss) acc = resultSizeAcc ss (acc + size s)
  36.         val rlen = resultSizeAcc ss 0
  37.         val r = create_string_ rlen
  38.         fun loop [] i = ()
  39.           | loop (s::ss) i =
  40.         let val slen = size s in
  41.             blit_string_ s 0 r i slen;
  42.             loop ss (i + slen)
  43.         end
  44.     in loop ss 0; r end;
  45. end;
  46.  
  47. exception Abs   = Overflow
  48.       and Diff  = Overflow
  49.       and Exp   = Overflow
  50.       and Floor = Overflow
  51.       and Neg   = Overflow
  52.       and Prod  = Overflow
  53.       and Sum   = Overflow
  54.       and Quot  = Overflow
  55.       and Mod   = Div;
  56.  
  57. prim_val sqrt   : real -> real = 1 "sml_sqrt";
  58. prim_val sin    : real -> real = 1 "sml_sin";
  59. prim_val cos    : real -> real = 1 "sml_cos";
  60. prim_val arctan : real -> real = 1 "atan_float";
  61. prim_val exp    : real -> real = 1 "sml_exp";
  62. prim_val ln     : real -> real = 1 "sml_ln";
  63.  
  64. type instream = BasicIO.instream and outstream = BasicIO.outstream
  65.  
  66. val std_in = BasicIO.std_in
  67. fun open_in s = BasicIO.open_in s
  68. fun input(is, n) = BasicIO.input (is, n)
  69. fun lookahead is = BasicIO.lookahead is
  70. fun close_in is = BasicIO.close_in is
  71. fun end_of_stream is = BasicIO.end_of_stream is
  72.  
  73. val std_out = BasicIO.std_out
  74. fun open_out s = BasicIO.open_out s
  75. fun output(os, s) = BasicIO.output(os, s)
  76. fun close_out os = BasicIO.close_out os
  77.