author | wenzelm |
Thu, 23 Jan 2025 22:19:30 +0100 | |
changeset 81960 | 326ecfc079a6 |
parent 80853 | a34eca8caccb |
permissions | -rw-r--r-- |
67205 | 1 |
(* Title: Pure/ML/ml_init.ML |
62818 | 2 |
Author: Makarius |
3 |
||
67205 | 4 |
Initial ML environment. |
62818 | 5 |
*) |
6 |
||
7 |
val seconds = Time.fromReal; |
|
8 |
||
9 |
val _ = |
|
10 |
List.app ML_Name_Space.forget_val |
|
78740
45ff003d337c
discontinue obsolete "Interrupt" constructor (NB: catch-all pattern produces ML compiler error);
wenzelm
parents:
78650
diff
changeset
|
11 |
["isSome", "getOpt", "valOf", "foldl", "foldr", "print", "explode", "concat", "Interrupt"]; |
62818 | 12 |
|
13 |
val ord = SML90.ord; |
|
14 |
val chr = SML90.chr; |
|
15 |
val raw_explode = SML90.explode; |
|
63925 | 16 |
val implode = String.concat; |
62818 | 17 |
|
18 |
val pointer_eq = PolyML.pointerEq; |
|
19 |
||
20 |
val error_depth = PolyML.error_depth; |
|
21 |
||
62923 | 22 |
structure Basic_Exn: BASIC_EXN = Exn; |
23 |
open Basic_Exn; |
|
67206
b8f30228a55b
minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents:
67205
diff
changeset
|
24 |
|
b8f30228a55b
minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents:
67205
diff
changeset
|
25 |
structure String = |
b8f30228a55b
minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents:
67205
diff
changeset
|
26 |
struct |
b8f30228a55b
minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents:
67205
diff
changeset
|
27 |
open String; |
b8f30228a55b
minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents:
67205
diff
changeset
|
28 |
fun substring (s, i, n) = |
b8f30228a55b
minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents:
67205
diff
changeset
|
29 |
if n = 1 then String.str (String.sub (s, i)) |
b8f30228a55b
minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents:
67205
diff
changeset
|
30 |
else String.substring (s, i, n); |
b8f30228a55b
minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents:
67205
diff
changeset
|
31 |
end; |
75594 | 32 |
|
33 |
structure Substring = |
|
34 |
struct |
|
35 |
open Substring; |
|
36 |
val empty = full ""; |
|
80853
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
37 |
|
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
38 |
local |
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
39 |
val chars = Vector.tabulate (Char.maxOrd, Substring.full o String.str o Char.chr); |
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
40 |
in |
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
41 |
fun full str = |
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
42 |
(case String.size str of |
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
43 |
0 => empty |
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
44 |
| 1 => Vector.sub (chars, Char.ord (String.sub (str, 0))) |
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
45 |
| _ => Substring.full str); |
75594 | 46 |
end; |
80853
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
47 |
|
a34eca8caccb
minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents:
78740
diff
changeset
|
48 |
end; |