src/Tools/isac/Frontend/states.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 13 Sep 2010 17:21:22 +0200
branchisac-update-Isa09-2
changeset 38006 16d56796f5a0
parent 37986 7b1d2366c191
child 38007 d679c1f837a7
permissions -rw-r--r--
ref --> Unsynchronized.ref done
neuper@37906
     1
(* states for calculation in global refs
neuper@37906
     2
   use"../states.sml";
neuper@37906
     3
   use"states.sml";
neuper@37906
     4
   *)
neuper@37906
     5
neuper@37906
     6
(*
neuper@37906
     7
type hide = (pblID * 
neuper@37906
     8
	     string list * (*hide: tacs + 
neuper@37906
     9
					  "ALL",       .. result immediately
neuper@37906
    10
					  "MODELPBL",  .. modeling hidden
neuper@37906
    11
					  "SPEC",      .. specifying hidden
neuper@37906
    12
		                          "MODELMET",  .. (additional itms !)
neuper@37906
    13
					  "APPLY",     .. solving hidden
neuper@37906
    14
		                    detail: rls
neuper@37906
    15
				   "Rewrite_*" (as strings) must _not_ be ..
neuper@37906
    16
				   .. contained in this list, rls _only_ !*)
neuper@37906
    17
		    bool)         (*inherit to children in pbl-herarchy*)
neuper@37906
    18
	       list;
neuper@37906
    19
neuper@37906
    20
(*. points a pbl/metID to a sub-hierarchy of key ?.*)
neuper@37906
    21
fun is_child_of child key =
neuper@37906
    22
    let fun is_ch [] [] = true     (*is child of itself*)
neuper@37906
    23
	  | is_ch (c::_) [] = true
neuper@37906
    24
	  | is_ch [] (k::_) = false
neuper@37906
    25
	  | is_ch (c::cs) (k::ks) = 
neuper@37906
    26
	    if c = k then is_ch cs ks else false
neuper@37906
    27
    in is_ch (rev child) (rev key) end;
neuper@37906
    28
(*
neuper@37986
    29
is_child_of ["root'","univar","equation"] ["univar","equation"];
neuper@37906
    30
val it = true : bool
neuper@37986
    31
is_child_of ["root'","univar","equation"] ["system","equation"];
neuper@37906
    32
val it = false : bool
neuper@37906
    33
is_child_of ["equation"] ["system","equation"];
neuper@37906
    34
val it = false : bool
neuper@37986
    35
is_child_of ["root'","univar","equation"] ["linear","univar","equation"];
neuper@37906
    36
val it = false : bool
neuper@37906
    37
*)
neuper@37906
    38
neuper@37906
    39
(*.what tactics have to be hidden (in model/specify these may be several).*)
neuper@37906
    40
datatype hid = 
neuper@37906
    41
	 Show      (**)
neuper@37906
    42
       | Hundef	   (**)
neuper@37906
    43
       | Htac	   (*a tactic has to be hidden*)
neuper@37906
    44
       | Hmodel	   (*the model of the (sub)problem has to be hidden*)
neuper@37906
    45
       | Hspecify  (*the specification of the (sub)problem has to be hidden*)
neuper@37906
    46
       | Happly;   (*solving the (sub)problem has to be hidden*)
neuper@37906
    47
neuper@37906
    48
(*. search all pbls if there is some tactic or model/spec/calc to hide .*)
neuper@37906
    49
fun is_hid pblID arg [] = Show
neuper@37906
    50
  | is_hid pblID arg ((pblID', strs, inherit)::pts) = 
neuper@37906
    51
    let fun is_mem arg = 
neuper@37906
    52
	    if arg mem strs then Htac
neuper@37906
    53
	    else if arg mem ["Add_Given","Add_Find","Add_Relation"] 
neuper@37906
    54
		    andalso "MODEL" mem strs then Hmodel
neuper@37906
    55
	    else if arg mem ["Specify_Theory","Specify_Problem",
neuper@37906
    56
			     "Specify_Method"] 
neuper@37906
    57
		    andalso "SPEC" mem strs then Hspecify
neuper@37906
    58
	    else if "APPLY" mem strs then Htac 
neuper@37906
    59
	    else Hundef
neuper@37906
    60
    in if inherit then
neuper@37906
    61
	   if is_child_of (pblID:pblID) pblID' 
neuper@37906
    62
	   then case is_mem arg of Hundef => is_hid pblID arg (pts:hide)
neuper@37906
    63
				 | hid => hid
neuper@37906
    64
	   else is_hid pblID arg pts
neuper@37906
    65
       else if pblID = pblID' 
neuper@37906
    66
       then case is_mem arg of Hundef => is_hid pblID arg (pts:hide)
neuper@37906
    67
			     | hid => hid
neuper@37906
    68
       else is_hid pblID arg pts
neuper@37906
    69
    end;
neuper@37906
    70
(*val hide = [([],["Refine_Tacitly"],true),
neuper@37906
    71
	    (["univar","equation"],["Apply_Method","Model_Problem","SPEC"],
neuper@37906
    72
	     false)]
neuper@37906
    73
	   :hide;
neuper@37906
    74
is_hid [] "Rewrite" hide;
neuper@37906
    75
val it = Show
neuper@37906
    76
is_hid ["any","problem"] "Refine_Tacitly" hide;
neuper@37906
    77
val it = Htac
neuper@37986
    78
is_hid ["root'","univar","equation"] "Apply_Method" hide;
neuper@37906
    79
val it = Show
neuper@37906
    80
is_hid ["univar","equation"] "Apply_Method" hide;
neuper@37906
    81
val it = Htac
neuper@37906
    82
is_hid ["univar","equation"] "Specify_Problem" hide;
neuper@37906
    83
val it = Hspecify
neuper@37906
    84
*)
neuper@37906
    85
neuper@37906
    86
fun is_hide pblID (tac as (Subproblem (_,pI))) (det:detail) = 
neuper@37906
    87
    is_hid pblID "SELF" det
neuper@37906
    88
  | is_hide pblID (tac as (Rewrite (thmID,_))) det = 
neuper@37906
    89
    is_hid pblID thmID det
neuper@37906
    90
  | is_hide pblID (tac as (Rewrite_Inst (_,(thmID,_)))) det = 
neuper@37906
    91
    is_hid pblID thmID det
neuper@37906
    92
  | is_hide pblID (tac as (Rewrite_Set rls)) det = 
neuper@37906
    93
    is_hid pblID rls det
neuper@37906
    94
  | is_hide pblID (tac as (Rewrite_Set_Inst (_,rls))) det = 
neuper@37906
    95
    is_hid pblID rls det
neuper@37906
    96
  | is_hide pblID tac det = is_hid pblID (tac2IDstr tac) det;
neuper@37906
    97
(*val hide = [([],["Refine_Tacitly"],true),
neuper@37906
    98
	    (["univar","equation"],["Apply_Method","Model_Problem",
neuper@37906
    99
				    "SPEC","SELF"],
neuper@37906
   100
	     false)]
neuper@37906
   101
	   :hide;
neuper@37906
   102
is_hide [] (Rewrite ("","")) hide;
neuper@37906
   103
val it = Show
neuper@37906
   104
is_hide ["any","problem"] (Refine_Tacitly []) hide;
neuper@37906
   105
val it = Htac
neuper@37986
   106
is_hide ["root'","univar","equation"] (Apply_Method []) hide;
neuper@37906
   107
val it = Show
neuper@37906
   108
is_hide ["univar","equation"] (Apply_Method []) hide;
neuper@37906
   109
val it = Htac
neuper@37906
   110
is_hide ["univar","equation"] (Specify_Problem []) hide;
neuper@37906
   111
val it = Hspecify
neuper@37906
   112
is_hide ["univar","equation"] (Subproblem (e_domID,["univar","equation"]))hide;
neuper@37906
   113
val it = Htac
neuper@37906
   114
is_hide ["equation"] (Subproblem (e_domID,["univar","equation"]))hide;
neuper@37906
   115
val it = Show
neuper@37906
   116
*)
neuper@37906
   117
neuper@37906
   118
neuper@37906
   119
(*. search all pbls in detail if there is some rls' to be detailed .*)
neuper@37906
   120
fun is_det pblID arg [] = false
neuper@37906
   121
  | is_det pblID arg ((pblID', rlss, inherit)::pts) = 
neuper@37906
   122
    if inherit then
neuper@37906
   123
	   if is_child_of (pblID:pblID) pblID' 
neuper@37906
   124
	   then if arg mem rlss then true
neuper@37906
   125
		else is_det pblID arg (pts:detail)
neuper@37906
   126
	   else is_det pblID arg pts
neuper@37906
   127
       else if pblID = pblID' 
neuper@37906
   128
	   then if arg mem rlss then true
neuper@37906
   129
		else is_det pblID arg (pts:detail)
neuper@37906
   130
       else is_det pblID arg pts;
neuper@37906
   131
neuper@37906
   132
(*fun is_detail pblID (tac as (Subproblem (_,pI))) (det:detail) = 
neuper@37906
   133
    is_det pblID "SELF" det*)
neuper@37906
   134
fun is_detail pblID (tac as (Rewrite_Set rls)) det = 
neuper@37906
   135
    is_det pblID rls det
neuper@37906
   136
  | is_detail pblID (tac as (Rewrite_Set_Inst (_,rls))) det = 
neuper@37906
   137
    is_det pblID rls det
neuper@37906
   138
  | is_detail _ _ _ = false;
neuper@37906
   139
----------------------------------------*)
neuper@37906
   140
neuper@37906
   141
type iterID = int;
neuper@37906
   142
type calcID = int;
neuper@37906
   143
neuper@37906
   144
(*FIXME.WN.9.03: ev. resdesign calcstate + pos for CalcIterator
neuper@37906
   145
type state = 
neuper@37906
   146
     (*pos' *          set by the CalcIterator ---> for each user*)
neuper@37906
   147
     calcstate;       (*to which ev.included 'preview' tac_s could be applied*)
neuper@37906
   148
val e_state = (e_pos', e_calcstate):state;
neuper@38006
   149
val states = Unsynchronized.ref ([]:(iterID * (calcID * state) list) list);
neuper@37906
   150
*)
neuper@37906
   151
neuper@37906
   152
val states = 
neuper@37906
   153
    ref ([]:(calcID * 
neuper@37906
   154
	     (calcstate * 
neuper@37906
   155
	      (iterID *       (*1 sets the 'active formula'*)
neuper@37906
   156
	       pos'           (*for iterator of a user     *)
neuper@37906
   157
	       ) list)) list);
neuper@37906
   158
(*
neuper@37906
   159
states:= [(3,(e_calcstate, [(1,e_pos'),
neuper@37906
   160
			    (3,e_pos')])),
neuper@37906
   161
	  (4,(e_calcstate, [(1,e_pos'),
neuper@37906
   162
			    (2,e_pos')]))];
neuper@37906
   163
*)
neuper@37906
   164
neuper@37906
   165
(** create new instances of users and ptrees
neuper@37906
   166
   new keys are the lowest possible in the association list **)
neuper@37906
   167
neuper@37906
   168
(* add users *)
neuper@37906
   169
fun new_key u n = case assoc (u, n) of 
neuper@37926
   170
  NONE => n 
neuper@37926
   171
| SOME _ => new_key u (n+1);
neuper@37906
   172
(*///10.10
neuper@37906
   173
fun get_calcID (u:(calcID * (calcstate * (iterID * pos') list)) list) = 
neuper@37906
   174
    (new_key u 1):calcID;*)
neuper@37906
   175
(*
neuper@37906
   176
val new_iterID = get_calcID (!states);
neuper@37906
   177
val it = 1 : int
neuper@37906
   178
states:= (!states) @ [(new_iterID, [])];
neuper@37906
   179
!states;
neuper@37906
   180
val it = [(3,[(#,#),(#,#)]),(4,[(#,#),(#,#)]),(1,[])]
neuper@37906
   181
*)
neuper@37906
   182
neuper@37906
   183
(*///7.10.03/// add states to a users active states
neuper@37906
   184
fun get_calcID (uI:iterID) (p:(iterID * (calcID * state) list) list) = 
neuper@37906
   185
  case assoc (p, uI) of 
neuper@37926
   186
    NONE => raise error ("get_calcID: no iterID " ^ 
neuper@37906
   187
			  (string_of_int uI))
neuper@37926
   188
  | SOME ps => (new_key ps 1):calcID;
neuper@37906
   189
> get_calcID 1 (!states);  
neuper@37906
   190
val it = 1 : calcID
neuper@37906
   191
*)
neuper@37906
   192
(* add users to a calcstate *)
neuper@37906
   193
fun get_iterID (cI:calcID) 
neuper@37906
   194
	       (p:(calcID * (calcstate * (iterID * pos') list)) list) = 
neuper@37906
   195
  case assoc (p, cI) of
neuper@37926
   196
    NONE => raise error ("get_iterID: no iterID " ^ (string_of_int cI))
neuper@37926
   197
  | SOME (_, us) => (new_key us 1):iterID;
neuper@37906
   198
(* get_iterID 3 (!states);
neuper@37906
   199
val it = 2 : iterID*)
neuper@37906
   200
neuper@37906
   201
neuper@37906
   202
(** retrieve, update, delete a state by iterID, calcID **)
neuper@37906
   203
neuper@37906
   204
(*//////7.10.
neuper@37906
   205
fun get_cal (uI:iterID) (pI:calcID) (p:(iterID * (calcID * state) list) list) =
neuper@37906
   206
  (the (assoc2 (p,(uI, pI)))) 
neuper@37906
   207
  handle _ => raise error ("get_state " ^ (string_of_int uI) ^
neuper@37906
   208
			     " " ^ (string_of_int pI) ^ " not existent");
neuper@37906
   209
> get_cal 3 1 (!states);
neuper@37906
   210
val it = (((EmptyPtree,(#,#)),[]),([],[])) : state
neuper@37906
   211
*)
neuper@37906
   212
neuper@37906
   213
(*///7.10.
neuper@37906
   214
fun get_state (uI:iterID) (pI:calcID) = get_cal uI pI (!states);
neuper@37906
   215
fun get_calc  (uI:iterID) (pI:calcID) = (snd o (get_cal uI pI)) (!states);
neuper@37906
   216
*)
neuper@37906
   217
fun get_calc  (cI:calcID) = 
neuper@37906
   218
    case assoc (!states, cI) of 
neuper@37926
   219
	NONE => raise error ("get_calc "^(string_of_int cI)^" not existent")
neuper@37926
   220
      | SOME (c, _) => c;
neuper@37906
   221
fun get_pos (cI:calcID) (uI:iterID) = 
neuper@37906
   222
    case assoc (!states, cI) of 
neuper@37926
   223
	NONE => raise error ("get_pos: calc " ^ (string_of_int cI) 
neuper@37906
   224
			     ^ " not existent")
neuper@37926
   225
      | SOME (_, us) => 
neuper@37906
   226
	(case assoc (us, uI) of 
neuper@37926
   227
	    NONE => raise error ("get_pos: user " ^ (string_of_int uI) 
neuper@37906
   228
				 ^ " not existent")
neuper@37926
   229
	  | SOME p => p);
neuper@37906
   230
neuper@37906
   231
neuper@37906
   232
fun del_assoc ([],_) = []
neuper@37906
   233
  | del_assoc a =
neuper@37906
   234
  let fun del ([], key) ps = ps
neuper@37906
   235
	| del ((keyi, xi) :: pairs, key) ps =
neuper@37906
   236
    if key = keyi then ps @ pairs
neuper@37906
   237
    else del (pairs, key) (ps @ [(keyi, xi)])
neuper@37906
   238
  in del a [] end;
neuper@37906
   239
(*
neuper@37906
   240
> val ps =  [(1,"1"),(2,"2"),(3,"3"),(4,"4")];     
neuper@37906
   241
> del_assoc (ps,3);
neuper@37906
   242
val it = [(1,"1"),(2,"2"),(4,"4")] : (int * string) list
neuper@37906
   243
*)
neuper@37906
   244
neuper@37906
   245
(* delete doesn't report non existing elements *)
neuper@37906
   246
(*/////7.10.
neuper@37906
   247
fun del_assoc2 (uI:iterID) (pI:calcID) ps =
neuper@37906
   248
  let val new_ps = del_assoc (the (assoc (ps, uI)), pI)
neuper@37906
   249
  in overwrite (ps, (uI, new_ps)) end;*)
neuper@37906
   250
(*
neuper@37906
   251
> states:= del_assoc2 4 41 (!states);
neuper@37906
   252
> !states;
neuper@37906
   253
val it = [(3,[(#,#),(#,#),(#,#)]),(4,[(#,#)]),(1,[(#,#)])] : states
neuper@37906
   254
neuper@37906
   255
> del_user 3;
neuper@37906
   256
> !states;
neuper@37906
   257
val it = [(4,[(#,#)]),(1,[(#,#)])] : states
neuper@37906
   258
*)
neuper@37906
   259
fun del_assoc2 (cI:calcID) (uI:iterID) ps =
neuper@37906
   260
    case assoc (ps, cI) of
neuper@37926
   261
	NONE => ps
neuper@37926
   262
      | SOME (cs, us) => 
neuper@37906
   263
	overwrite (ps, (cI, (cs, del_assoc (us, uI))));
neuper@37906
   264
(*
neuper@37906
   265
> del_assoc2 4 1 (!states);
neuper@37906
   266
val it =
neuper@37906
   267
   [(3, (((EmptyPtree, ([], Und)), []), [(1, ([], Und)), (3, ([], Und))])),
neuper@37906
   268
    (4, (((EmptyPtree, ([], Und)), []), [(2, ([], Und))]))]*)
neuper@37906
   269
neuper@37906
   270
(*///7.10.
neuper@37906
   271
fun overwrite2 (ps, (((uI:iterID), (pI:calcID)), p)) = 
neuper@37906
   272
  let val new_ps = overwrite (the (assoc (ps, uI)), (pI, p))
neuper@37906
   273
  in (overwrite (ps, (uI, new_ps)))
neuper@37906
   274
    handle _ => raise error ("overwrite2 " ^ (string_of_int uI) ^
neuper@37906
   275
			      " " ^ (string_of_int pI) ^ " not existent")
neuper@37906
   276
  end;*)
neuper@37906
   277
fun overwrite2 (ps, (((cI:calcID), (uI:iterID)), p)) =
neuper@37906
   278
    case assoc (ps, cI) of
neuper@37926
   279
	NONE => 
neuper@37906
   280
	raise error ("overwrite2: calc " ^ (string_of_int uI) ^" not existent")
neuper@37926
   281
      | SOME (cs, us) =>
neuper@37906
   282
	overwrite (ps, (cI ,(cs, overwrite (us, (uI, p)))));
neuper@37906
   283
neuper@37906
   284
fun upd_calc (cI:calcID) cs =
neuper@37906
   285
    case assoc (!states, cI) of 
neuper@37926
   286
	NONE => raise error ("upd_calc "^(string_of_int cI)^" not existent")
neuper@37926
   287
      | SOME (_, us) => states:= overwrite (!states, (cI, (cs, us)));
neuper@37906
   288
(*WN051210 testing before initac: only 1 taci in calcstate so far:
neuper@37906
   289
fun upd_calc (cI:calcID) (cs as (_, tacis):calcstate) =
neuper@37906
   290
    (if length tacis > 1 
neuper@37906
   291
     then raise error ("upd_calc, |tacis|>1: "^tacis2str tacis) 
neuper@37906
   292
     else ();
neuper@37906
   293
    case assoc (!states, cI) of 
neuper@37926
   294
	NONE => raise error ("upd_calc "^(string_of_int cI)^" not existent")
neuper@37926
   295
      | SOME (_, us) => states:= overwrite (!states, (cI, (cs, us)))
neuper@37906
   296
			);*)
neuper@37906
   297
neuper@37906
   298
neuper@37906
   299
(*///7.10.
neuper@37906
   300
fun upd_tacis (uI:iterID) (pI:calcID) tacis =
neuper@37906
   301
   let val (p, (ptp,_)) = get_state uI pI 
neuper@37906
   302
   in states:= 
neuper@37906
   303
      overwrite2 ((!states), ((uI, pI), (p, (ptp, tacis)))) end;*)
neuper@37906
   304
fun upd_tacis (cI:calcID) tacis =
neuper@37906
   305
    case assoc (!states, cI) of 
neuper@37926
   306
	NONE => 
neuper@37906
   307
	raise error ("upd_tacis: calctree "^(string_of_int cI)^" not existent")
neuper@37926
   308
      | SOME ((ptp,_), us) => 
neuper@37906
   309
	states:= overwrite (!states, (cI, ((ptp, tacis), us)));
neuper@37906
   310
(*///7.10.
neuper@37906
   311
fun upd_ipos (uI:iterID) (pI:calcID) (ip:pos') =
neuper@37906
   312
   let val (_, calc) = get_state uI pI 
neuper@37906
   313
   in states:= overwrite2 ((!states), ((uI, pI), (ip, calc))) end;*)
neuper@37906
   314
fun upd_ipos (cI:calcID) (uI:iterID) (ip:pos') =
neuper@37906
   315
    case assoc (!states, cI) of 
neuper@37926
   316
	NONE => 
neuper@37906
   317
	raise error ("upd_ipos: calctree "^(string_of_int cI)^" not existent")
neuper@37926
   318
      | SOME (cs, us) => 
neuper@37906
   319
	states:= overwrite2 (!states, ((cI, uI), ip));
neuper@37906
   320
neuper@37906
   321
neuper@37906
   322
(** add and delete calcs **)
neuper@37906
   323
neuper@37906
   324
(*///7.10
neuper@37906
   325
fun add_pID (uI:iterID) (s:state) (p:(iterID * (calcID * state) list) list) = 
neuper@37906
   326
  let val new_ID = get_calcID uI p;
neuper@37906
   327
    val new_states = (the (assoc (p, uI))) @ [(new_ID, s)];
neuper@37906
   328
  in (new_ID, (overwrite (p, (uI, new_states)))) end;*)
neuper@37906
   329
(*
neuper@37906
   330
> val (new_calcID, new_states) = add_pID 1 (!states);
neuper@37906
   331
> states:= new_states;
neuper@37906
   332
> !states;
neuper@37906
   333
val it = [(3,[(#,#),(#,#)]),(4,[(#,#),(#,#)]),(1,[(#,#)])] : states
neuper@37906
   334
> val (new_calcID, new_states) = add_pID 3 (!states);
neuper@37906
   335
> states:= new_states;
neuper@37906
   336
> !states;
neuper@37906
   337
val it = [(3,[(#,#),(#,#),(#,#)]),(4,[(#,#),(#,#)]),(1,[(#,#)])] : states
neuper@37906
   338
> assoc2 (!states, (3, 1));
neuper@37926
   339
val it = SOME EmptyPtree : ptree option
neuper@37906
   340
> assoc2 (!states, (3, 2));
neuper@37926
   341
val it = NONE : ptree option
neuper@37906
   342
*)
neuper@37906
   343
(*///7.10
neuper@37906
   344
fun add_calc (uI:iterID) (s:state) = 
neuper@37906
   345
    let val (new_calcID, new_calcs) = add_pID uI s (!states)
neuper@37906
   346
    in states:= new_calcs; 
neuper@37906
   347
    new_calcID end; *)
neuper@37906
   348
fun add_user (cI:calcID) = 
neuper@37906
   349
    case assoc (!states, cI) of 
neuper@37926
   350
	NONE => 
neuper@37906
   351
	raise error ("add_user: calctree "^(string_of_int cI)^" not existent")
neuper@37926
   352
      | SOME (cs, us) => 
neuper@37906
   353
	let val new_uI = new_key us 1
neuper@37906
   354
	in states:= overwrite2 (!states, ((cI, new_uI), e_pos'));
neuper@37906
   355
	   new_uI:iterID end;
neuper@37906
   356
neuper@37906
   357
(*///10.10.
neuper@37906
   358
fun del_calc (uI:iterID) (pI:calcID) = 
neuper@37906
   359
    (states:= del_assoc2 uI pI (!states); pI);*)
neuper@37906
   360
fun del_user (cI:calcID) (uI:iterID) = 
neuper@37906
   361
    (states:= del_assoc2 cI uI (!states); uI);
neuper@37906
   362
neuper@37906
   363
neuper@37906
   364
(** add and delete calculations **)
neuper@37906
   365
(**///7.10 add and delete users **)
neuper@37906
   366
(*///7.10
neuper@37906
   367
fun add_user () = 
neuper@37906
   368
  let val new_uI = get_calcID (!states)
neuper@37906
   369
  in states:= (!states) @ [(new_uI, [])];
neuper@37906
   370
     new_uI end;*)
neuper@37906
   371
fun add_calc (cs:calcstate) = 
neuper@37906
   372
  let val new_cI = new_key (!states) 1
neuper@37906
   373
  in states:= (!states) @ [(new_cI, (cs, []))];
neuper@37906
   374
     new_cI:calcID end;
neuper@37906
   375
neuper@37906
   376
(* delete doesn't report non existing elements *)
neuper@37906
   377
(*///7.10
neuper@37906
   378
fun del_user (uI:userID) = 
neuper@37906
   379
    (states:= del_assoc (!states, uI); uI);*)
neuper@37906
   380
fun del_calc (cI:calcID) = 
neuper@37906
   381
    (states:= del_assoc (!states, cI); cI:calcID);
neuper@37906
   382
neuper@37906
   383
(* -------------- test all exported funs -------------- 
neuper@37906
   384
///7.10
neuper@37906
   385
Compiler.Control.Print.printDepth:=8;
neuper@37906
   386
states:=[];
neuper@37906
   387
add_user (); add_user (); !states;
neuper@37906
   388
ML> val it = 1 : userID
neuper@37906
   389
ML> val it = 2 : userID
neuper@37906
   390
ML> val it = [(1,[]),(2,[])]
neuper@37906
   391
neuper@37906
   392
val (hide,detail) = ([(["pI"],["tac"],true)]:hide,
neuper@37906
   393
		       [(["pI"],["tac"],true)]:detail);
neuper@37906
   394
add_calc 1 e_state; 
neuper@37906
   395
add_calc 1 (e_calcstate,(hide,detail)); !states;
neuper@37906
   396
ML> val it = 1 : calcID
neuper@37906
   397
ML> val it = 2 : calcID
neuper@37906
   398
ML> val it =
neuper@37906
   399
  [(1,
neuper@37906
   400
    [(1,(((EmptyPtree,(#,#)),[]),([],[]))),
neuper@37906
   401
     (2,(((EmptyPtree,(#,#)),[]),([(#,#,#)],[(#,#,#)])))]),(2,[])]
neuper@37906
   402
neuper@37906
   403
val (pt,(p,p_)) = (EmptyPtree,e_pos');
neuper@37906
   404
val (pt,_) = cappend_problem pt p Uistate ([],e_spec);
neuper@37906
   405
upd_calc 1 2 ((pt,(p,p_)),[]); !states;
neuper@37906
   406
ML> val it =
neuper@37906
   407
  [(1,
neuper@37906
   408
    [(1,(((EmptyPtree,(#,#)),[]),([],[]))),
neuper@37906
   409
     (2,(((Nd #,(#,#)),[]),([(#,#,#)],[(#,#,#)])))]),(2,[])]
neuper@37906
   410
(*                          ~~~~~~~~~~~~~~~~~~~~ unchanged !!!*)
neuper@37906
   411
neuper@37906
   412
get_state 1 1; get_state 1 2;
neuper@37906
   413
ML> val it = (((EmptyPtree,([],Und)),[]),([],[])) : state
neuper@37906
   414
ML> val it =
neuper@37906
   415
  (((Nd
neuper@37906
   416
       (PblObj
neuper@37906
   417
          {branch=NoBranch,cell=[],env=(#,#,#,#),loc=(#,#),meth=[],
neuper@37906
   418
           model={Find=#,Given=#,Relate=#,Where=#,With=#},origin=(#,#),
neuper@37906
   419
           ostate=Incomplete,probl=[],result=(#,#),spec=(#,#,#)},[]),([],Und)),
neuper@37906
   420
    []),([(["pI"],["tac"],true)],[(["pI"],["tac"],true)])) : state
neuper@37906
   421
neuper@37906
   422
del_calc 2 1 (*non existent - NO msg!*); del_calc 1 2; !states;
neuper@37906
   423
ML> val it = [(1,[(1,(((EmptyPtree,(#,#)),[]),([],[])))]),(2,[])]
neuper@37906
   424
neuper@37906
   425
del_user 1; !states;
neuper@37906
   426
ML> val it = [(2,[])]
neuper@37906
   427
neuper@37906
   428
add_user (); add_user (); !states;
neuper@37906
   429
ML> val it = 1 : userID
neuper@37906
   430
ML> val it = 3 : userID
neuper@37906
   431
ML> val it = [(2,[]),(1,[]),(3,[])]
neuper@37906
   432
*)
neuper@37906
   433
neuper@37906
   434
neuper@37906
   435
(* -------------- test all exported funs -------------- 
neuper@37906
   436
print_depth 9;
neuper@37906
   437
states:=[];
neuper@37906
   438
add_calc e_calcstate; add_calc e_calcstate; !states;
neuper@37906
   439
|val it = 1 : calcID
neuper@37906
   440
|val it = 2 : calcID
neuper@37906
   441
|val it =
neuper@37906
   442
|   [(1, (((EmptyPtree, ([], Und)), []), [])),
neuper@37906
   443
|      (2, (((EmptyPtree, ([], Und)), []), []))]
neuper@37906
   444
neuper@37906
   445
add_user 2; add_user 2; !states; 
neuper@37906
   446
|val it = 1 : userID
neuper@37906
   447
|val it = 2 : userID
neuper@37906
   448
|val it =
neuper@37906
   449
|   [(1, (((EmptyPtree, ([], Und)), []), [])),
neuper@37906
   450
|      (2, (((EmptyPtree, ([], Und)), []), [(1, ([], Und)), (2, ([], Und))]))]
neuper@37906
   451
neuper@37906
   452
neuper@37906
   453
val cs = ((EmptyPtree, ([111], Und)), []) : calcstate;
neuper@37906
   454
upd_calc 1 cs; !states;
neuper@37906
   455
|val it =
neuper@37906
   456
|   [(1, (((EmptyPtree, ([111], Und)), []), [])),
neuper@37906
   457
|      (2, (((EmptyPtree, ([], Und)), []), [(1, ([], Und)), (2, ([], Und))]))]   
neuper@37906
   458
neuper@37906
   459
get_calc 1; get_calc 2;
neuper@37906
   460
|val it = ((EmptyPtree, ([111], Und)), []) : calcstate
neuper@37906
   461
|val it = ((EmptyPtree, ([], Und)), []) : calcstate
neuper@37906
   462
neuper@37906
   463
del_user 2 3 (*non existent - NO msg!*); del_user 2 1; !states;
neuper@37906
   464
|val it = 3 : userID
neuper@37906
   465
|val it = 1 : userID
neuper@37906
   466
|val it =
neuper@37906
   467
|   [(1, (((EmptyPtree, ([111], Und)), []), [])),
neuper@37906
   468
|      (2, (((EmptyPtree, ([], Und)), []), [(2, ([], Und))]))]
neuper@37906
   469
neuper@37906
   470
del_calc 1; !states;
neuper@37906
   471
|val it = 1 : calcID
neuper@37906
   472
|val it = [(2, (((EmptyPtree, ([], Und)), []), [(2, ([], Und))]))]
neuper@37906
   473
neuper@37906
   474
add_calc e_calcstate; add_calc e_calcstate; !states;
neuper@37906
   475
|val it = 1 : calcID
neuper@37906
   476
|val it = 3 : calcID
neuper@37906
   477
|val it =
neuper@37906
   478
|   [(2, (((EmptyPtree, ([], Und)), []), [(2, ([], Und))])),
neuper@37906
   479
|      (1, (((EmptyPtree, ([], Und)), []), [])),
neuper@37906
   480
|      (3, (((EmptyPtree, ([], Und)), []), []))]
neuper@37906
   481
neuper@37906
   482
add_user 2; !states;
neuper@37906
   483
|val it =
neuper@37906
   484
|   [(2, (((EmptyPtree, ([], Und)), []), [(2, ([], Und)), (1, ([], Und))])),
neuper@37906
   485
|      (1, (((EmptyPtree, ([], Und)), []), [])),
neuper@37906
   486
|      (3, (((EmptyPtree, ([], Und)), []), []))]
neuper@37906
   487
*)