src/Pure/pattern.ML
author paulson
Wed Mar 05 10:04:45 1997 +0100 (1997-03-05)
changeset 2725 9453616d4b80
parent 2616 704b6c7432cf
child 2751 673c4eefd2e1
permissions -rw-r--r--
Declares eta_contract_atom; fixed comment; some tidying
clasohm@1460
     1
(*  Title: 	pattern
clasohm@0
     2
    ID:         $Id$
clasohm@1460
     3
    Author: 	Tobias Nipkow and Christine Heinzelmann, TU Muenchen
clasohm@0
     4
    Copyright   1993  TU Muenchen
clasohm@0
     5
clasohm@0
     6
Unification of Higher-Order Patterns.
clasohm@0
     7
clasohm@0
     8
See also:
clasohm@0
     9
Tobias Nipkow. Functional Unification of Higher-Order Patterns.
clasohm@0
    10
In Proceedings of the 8th IEEE Symposium Logic in Computer Science, 1993.
nipkow@678
    11
nipkow@678
    12
TODO: optimize red by special-casing it
clasohm@0
    13
*)
clasohm@0
    14
clasohm@0
    15
signature PATTERN =
paulson@1501
    16
  sig
clasohm@0
    17
  type type_sig
clasohm@0
    18
  type sg
clasohm@0
    19
  type env
paulson@2725
    20
  val eta_contract      : term -> term
paulson@2725
    21
  val eta_contract_atom : term -> term
paulson@2725
    22
  val match             : type_sig -> term * term
paulson@2725
    23
                          -> (indexname*typ)list * (indexname*term)list
paulson@2725
    24
  val matches           : type_sig -> term * term -> bool
paulson@2725
    25
  val unify             : sg * env * (term * term)list -> env
clasohm@0
    26
  exception Unif
clasohm@0
    27
  exception MATCH
clasohm@0
    28
  exception Pattern
paulson@1501
    29
  end;
clasohm@0
    30
paulson@1501
    31
structure Pattern : PATTERN =
clasohm@0
    32
struct
clasohm@0
    33
clasohm@0
    34
type type_sig = Type.type_sig
clasohm@0
    35
type sg = Sign.sg
clasohm@0
    36
type env = Envir.env
clasohm@0
    37
clasohm@0
    38
exception Unif;
clasohm@0
    39
exception Pattern;
clasohm@0
    40
clasohm@0
    41
fun occurs(F,t,env) = 
clasohm@0
    42
    let fun occ(Var(G,_))   = (case Envir.lookup(env,G) of
clasohm@0
    43
                                 Some(t) => occ t
clasohm@0
    44
                               | None    => F=G)
clasohm@0
    45
          | occ(t1$t2)      = occ t1 orelse occ t2
clasohm@0
    46
          | occ(Abs(_,_,t)) = occ t
clasohm@0
    47
          | occ _           = false
clasohm@0
    48
    in occ t end;
clasohm@0
    49
clasohm@0
    50
clasohm@0
    51
fun mapbnd f =
clasohm@0
    52
    let fun mpb d (Bound(i))     = if i < d then Bound(i) else Bound(f(i-d)+d)
clasohm@0
    53
          | mpb d (Abs(s,T,t))   = Abs(s,T,mpb(d+1) t)
nipkow@678
    54
          | mpb d ((u1 $ u2))    = (mpb d u1)$(mpb d u2)
nipkow@678
    55
          | mpb _ atom           = atom
clasohm@0
    56
    in mpb 0 end;
clasohm@0
    57
clasohm@0
    58
fun idx [] j     = ~10000
clasohm@0
    59
  | idx(i::is) j = if i=j then length is else idx is j;
clasohm@0
    60
clasohm@0
    61
fun at xs i = nth_elem (i,xs);
clasohm@0
    62
clasohm@0
    63
fun mkabs (binders,is,t)  =
clasohm@0
    64
    let fun mk(i::is) = let val (x,T) = nth_elem(i,binders)
clasohm@0
    65
                        in Abs(x,T,mk is) end 
clasohm@0
    66
          | mk []     = t
clasohm@0
    67
    in mk is end;
clasohm@0
    68
clasohm@0
    69
val incr = mapbnd (fn i => i+1);
clasohm@0
    70
clasohm@0
    71
fun ints_of []             = []
clasohm@0
    72
  | ints_of (Bound i ::bs) = 
clasohm@0
    73
      let val is = ints_of bs
berghofe@1576
    74
      in if i mem_int is then raise Pattern else i::is end
clasohm@0
    75
  | ints_of _              = raise Pattern;
clasohm@0
    76
clasohm@0
    77
clasohm@0
    78
fun app (s,(i::is)) = app (s$Bound(i),is)
clasohm@0
    79
  | app (s,[])      = s;
clasohm@0
    80
clasohm@0
    81
fun red (Abs(_,_,s)) (i::is) js = red s is (i::js)
nipkow@678
    82
  | red t            []      [] = t
nipkow@678
    83
  | red t            is      jn = app (mapbnd (at jn) t,is);
nipkow@678
    84
clasohm@0
    85
clasohm@0
    86
(* split_type ([T1,....,Tn]---> T,n,[]) = ([Tn,...,T1],T) *)
clasohm@0
    87
fun split_type (T,0,Ts)                    = (Ts,T)
clasohm@0
    88
  | split_type (Type ("fun",[T1,T2]),n,Ts) = split_type (T2,n-1,T1::Ts)
nipkow@678
    89
  | split_type _                           = error("split_type");
clasohm@0
    90
clasohm@0
    91
fun type_of_G (T,n,is) =
clasohm@0
    92
  let val (Ts,U) = split_type(T,n,[]) in map(at Ts)is ---> U end;
clasohm@0
    93
clasohm@0
    94
fun mkhnf (binders,is,G,js) = mkabs (binders, is, app(G,js));
clasohm@0
    95
clasohm@0
    96
fun mknewhnf(env,binders,is,F as (a,_),T,js) =
clasohm@0
    97
  let val (env',G) = Envir.genvar a (env,type_of_G(T,length is,js))
clasohm@0
    98
  in Envir.update((F,mkhnf(binders,is,G,js)),env') end;
clasohm@0
    99
clasohm@0
   100
clasohm@0
   101
fun devar env t = case strip_comb t of
clasohm@0
   102
        (Var(F,_),ys) =>
clasohm@0
   103
            (case Envir.lookup(env,F) of
clasohm@0
   104
               Some(t) => devar env (red t (ints_of  ys) []) 
clasohm@0
   105
             | None    => t)
clasohm@0
   106
      |  _            => t;
clasohm@0
   107
clasohm@0
   108
clasohm@0
   109
(* mk_proj_list(is) = [ |is| - k | 1 <= k <= |is| and is[k] >= 0 ] *)
clasohm@0
   110
fun mk_proj_list is =
clasohm@0
   111
    let fun mk(i::is,j) = if i >= 0 then j :: mk(is,j-1) else mk(is,j-1)
clasohm@0
   112
          | mk([],_)    = []
clasohm@0
   113
    in mk(is,length is - 1) end;
clasohm@0
   114
clasohm@0
   115
fun proj(s,env,binders,is) =
clasohm@0
   116
    let fun trans d i = if i<d then i else (idx is (i-d))+d;
clasohm@0
   117
        fun pr(s,env,d,binders) = (case devar env s of
clasohm@0
   118
              Abs(a,T,t) => let val (t',env') = pr(t,env,d+1,((a,T)::binders))
clasohm@0
   119
                            in (Abs(a,T,t'),env') end
clasohm@0
   120
            | t => (case strip_comb t of
clasohm@0
   121
                (c as Const _,ts) =>
clasohm@0
   122
                         let val (ts',env') = prs(ts,env,d,binders)
clasohm@0
   123
                         in (list_comb(c,ts'),env') end
clasohm@0
   124
                 | (f as Free _,ts) =>
clasohm@0
   125
                         let val (ts',env') = prs(ts,env,d,binders)
clasohm@0
   126
                         in (list_comb(f,ts'),env') end
clasohm@0
   127
                 | (Bound(i),ts) =>
clasohm@0
   128
                         let val j = trans d i
clasohm@0
   129
                         in if j < 0 then raise Unif
clasohm@0
   130
                            else let val (ts',env') = prs(ts,env,d,binders)
clasohm@0
   131
                                 in (list_comb(Bound j,ts'),env') end
clasohm@0
   132
                         end
clasohm@0
   133
                 | (Var(F as (a,_),Fty),ts) =>
clasohm@0
   134
                      let val js = ints_of ts;
clasohm@0
   135
                          val js' = map (trans d) js;
clasohm@0
   136
                          val ks = mk_proj_list js';
clasohm@0
   137
                          val ls = filter (fn i => i >= 0) js'
clasohm@0
   138
                          val Hty = type_of_G(Fty,length js,ks)
clasohm@0
   139
                          val (env',H) = Envir.genvar a (env,Hty)
clasohm@0
   140
                          val env'' =
clasohm@0
   141
                                Envir.update((F,mkhnf(binders,js,H,ks)),env')
clasohm@0
   142
                      in (app(H,ls),env'') end
clasohm@0
   143
                 | _  => raise Pattern))
clasohm@0
   144
        and prs(s::ss,env,d,binders) =
clasohm@0
   145
              let val (s',env1) = pr(s,env,d,binders)
clasohm@0
   146
                  val (ss',env2) = prs(ss,env1,d,binders)
clasohm@0
   147
              in (s'::ss',env2) end
clasohm@0
   148
          | prs([],env,_,_) = ([],env)
clasohm@0
   149
   in if downto0(is,length binders - 1) then (s,env)
clasohm@0
   150
      else pr(s,env,0,binders)
clasohm@0
   151
   end;
clasohm@0
   152
clasohm@0
   153
clasohm@0
   154
(* mk_ff_list(is,js) = [ length(is) - k | 1 <= k <= |is| and is[k] = js[k] ] *)
clasohm@0
   155
fun mk_ff_list(is,js) = 
clasohm@0
   156
    let fun mk([],[],_)        = [] 
clasohm@0
   157
          | mk(i::is,j::js, k) = if i=j then k :: mk(is,js,k-1)
clasohm@0
   158
                                        else mk(is,js,k-1)
nipkow@678
   159
          | mk _               = error"mk_ff_list"
clasohm@0
   160
    in mk(is,js,length is-1) end;
clasohm@0
   161
clasohm@0
   162
fun flexflex1(env,binders,F,Fty,is,js) =
clasohm@0
   163
  if is=js then env
clasohm@0
   164
  else let val ks = mk_ff_list(is,js)
clasohm@0
   165
       in mknewhnf(env,binders,is,F,Fty,ks) end;
clasohm@0
   166
clasohm@0
   167
fun flexflex2(env,binders,F,Fty,is,G,Gty,js) =
clasohm@0
   168
  let fun ff(F,Fty,is,G as (a,_),Gty,js) =
berghofe@1576
   169
            if js subset_int is
clasohm@0
   170
            then let val t= mkabs(binders,is,app(Var(G,Gty),map (idx is) js))
clasohm@0
   171
                 in Envir.update((F,t),env) end
berghofe@1576
   172
            else let val ks = is inter_int js
clasohm@0
   173
                     val Hty = type_of_G(Fty,length is,map (idx is) ks)
clasohm@0
   174
                     val (env',H) = Envir.genvar a (env,Hty)
clasohm@0
   175
                     fun lam(is) = mkabs(binders,is,app(H,map (idx is) ks));
clasohm@0
   176
                 in Envir.update((G,lam js), Envir.update((F,lam is),env'))
clasohm@0
   177
                 end;
clasohm@0
   178
  in if xless(G,F) then ff(F,Fty,is,G,Gty,js) else ff(G,Gty,js,F,Fty,is) end
clasohm@0
   179
clasohm@0
   180
val tsgr = ref(Type.tsig0);
clasohm@0
   181
clasohm@0
   182
fun unify_types(T,U, env as Envir.Envir{asol,iTs,maxidx}) =
clasohm@0
   183
  if T=U then env
nipkow@1435
   184
  else let val (iTs',maxidx') = Type.unify (!tsgr) maxidx iTs (U,T)
nipkow@1435
   185
       in Envir.Envir{asol=asol,maxidx=maxidx',iTs=iTs'} end
clasohm@0
   186
       handle Type.TUNIFY => raise Unif;
clasohm@0
   187
clasohm@0
   188
fun unif binders (env,(s,t)) = case (devar env s,devar env t) of
clasohm@0
   189
      (Abs(ns,Ts,ts),Abs(nt,Tt,tt)) =>
clasohm@0
   190
         let val name = if ns = "" then nt else ns
clasohm@0
   191
         in unif ((name,Ts)::binders) (env,(ts,tt)) end
clasohm@0
   192
    | (Abs(ns,Ts,ts),t) => unif ((ns,Ts)::binders) (env,(ts,(incr t)$Bound(0)))
clasohm@0
   193
    | (t,Abs(nt,Tt,tt)) => unif ((nt,Tt)::binders) (env,((incr t)$Bound(0),tt))
clasohm@0
   194
    | p => cases(binders,env,p)
clasohm@0
   195
clasohm@0
   196
and cases(binders,env,(s,t)) = case (strip_comb s,strip_comb t) of
clasohm@0
   197
       ((Var(F,Fty),ss),(Var(G,Gty),ts)) => 
clasohm@0
   198
         if F = G then flexflex1(env,binders,F,Fty,ints_of ss,ints_of ts)
clasohm@0
   199
                  else flexflex2(env,binders,F,Fty,ints_of ss,G,Gty,ints_of ts)
clasohm@0
   200
      | ((Var(F,_),ss),_)             => flexrigid(env,binders,F,ints_of ss,t)
clasohm@0
   201
      | (_,(Var(F,_),ts))             => flexrigid(env,binders,F,ints_of ts,s)
clasohm@0
   202
      | ((Const c,ss),(Const d,ts))   => rigidrigid(env,binders,c,d,ss,ts)
clasohm@0
   203
      | ((Free(f),ss),(Free(g),ts))   => rigidrigid(env,binders,f,g,ss,ts)
clasohm@0
   204
      | ((Bound(i),ss),(Bound(j),ts)) => rigidrigidB (env,binders,i,j,ss,ts) 
clasohm@0
   205
      | ((Abs(_),_),_)                => raise Pattern
clasohm@0
   206
      | (_,(Abs(_),_))                => raise Pattern
clasohm@0
   207
      | _                             => raise Unif
clasohm@0
   208
clasohm@0
   209
and rigidrigid (env,binders,(a,Ta),(b,Tb),ss,ts) =
clasohm@0
   210
      if a<>b then raise Unif
clasohm@0
   211
      else foldl (unif binders) (unify_types(Ta,Tb,env), ss~~ts)
clasohm@0
   212
clasohm@0
   213
and rigidrigidB (env,binders,i,j,ss,ts) =
clasohm@0
   214
     if i <> j then raise Unif else foldl (unif binders) (env ,ss~~ts)
clasohm@0
   215
clasohm@0
   216
and flexrigid (env,binders,F,is,t) =
clasohm@0
   217
      if occurs(F,t,env) then raise Unif
clasohm@0
   218
      else let val (u,env') = proj(t,env,binders,is)
clasohm@0
   219
           in Envir.update((F,mkabs(binders,is,u)),env') end;
clasohm@0
   220
clasohm@0
   221
fun unify(sg,env,tus) = (tsgr := #tsig(Sign.rep_sg sg);
clasohm@0
   222
                         foldl (unif []) (env,tus));
clasohm@0
   223
clasohm@0
   224
paulson@2725
   225
(*Eta-contract a term (fully)*)
clasohm@0
   226
fun eta_contract (Abs(a,T,body)) = 
paulson@2616
   227
      (case  eta_contract body  of
paulson@2616
   228
        body' as (f $ Bound 0) => 
paulson@2616
   229
	  if (0 mem_int loose_bnos f) then Abs(a,T,body')
paulson@2616
   230
	  else incr_boundvars ~1 f 
clasohm@0
   231
      | body' => Abs(a,T,body'))
clasohm@0
   232
  | eta_contract(f$t) = eta_contract f $ eta_contract t
clasohm@0
   233
  | eta_contract t = t;
clasohm@0
   234
clasohm@0
   235
paulson@2725
   236
(*Eta-contract a term from outside: just enough to reduce it to an atom*)
paulson@2725
   237
fun eta_contract_atom (t0 as Abs(a, T, body)) = 
paulson@2725
   238
      (case  eta_contract2 body  of
paulson@2725
   239
        body' as (f $ Bound 0) => 
paulson@2725
   240
	    if (0 mem_int loose_bnos f) then Abs(a,T,body')
paulson@2725
   241
	    else eta_contract_atom (incr_boundvars ~1 f)
paulson@2725
   242
      | _ => t0)
paulson@2725
   243
  | eta_contract_atom t = t
paulson@2725
   244
and eta_contract2 (f$t) = f $ eta_contract_atom t
paulson@2725
   245
  | eta_contract2 t     = eta_contract_atom t;
paulson@2725
   246
paulson@2725
   247
nipkow@678
   248
(* Pattern matching *)
clasohm@0
   249
exception MATCH;
clasohm@0
   250
clasohm@0
   251
(*First-order matching;  term_match tsig (pattern, object)
clasohm@0
   252
    returns a (tyvar,typ)list and (var,term)list.
clasohm@0
   253
  The pattern and object may have variables in common.
clasohm@0
   254
  Instantiation does not affect the object, so matching ?a with ?a+1 works.
paulson@2725
   255
  A Const does not match a Free of the same name! *)
nipkow@678
   256
fun fomatch tsig (pat,obj) =
clasohm@0
   257
  let fun typ_match args = (Type.typ_match tsig args)
clasohm@1460
   258
			   handle Type.TYPE_MATCH => raise MATCH;
clasohm@0
   259
      fun mtch (tyinsts,insts) = fn
clasohm@1460
   260
	(Var(ixn,T), t)  =>
clasohm@1460
   261
	  if loose_bvar(t,0) then raise MATCH
berghofe@1576
   262
	  else (case assoc_string_int(insts,ixn) of
clasohm@1460
   263
		  None => (typ_match (tyinsts, (T, fastype_of t)), 
clasohm@1460
   264
			   (ixn,t)::insts)
clasohm@1460
   265
		| Some u => if t aconv u then (tyinsts,insts) else raise MATCH)
clasohm@0
   266
      | (Free (a,T), Free (b,U)) =>
clasohm@1460
   267
	  if  a=b  then (typ_match (tyinsts,(T,U)), insts)  else raise MATCH
clasohm@0
   268
      | (Const (a,T), Const (b,U))  =>
clasohm@1460
   269
	  if  a=b  then (typ_match (tyinsts,(T,U)), insts)  else raise MATCH
clasohm@0
   270
      | (Bound i, Bound j)  =>
clasohm@0
   271
          if  i=j  then  (tyinsts,insts)  else raise MATCH
clasohm@0
   272
      | (Abs(_,T,t), Abs(_,U,u))  =>
clasohm@1460
   273
	  mtch (typ_match (tyinsts,(T,U)),insts) (t,u)
clasohm@0
   274
      | (f$t, g$u) => mtch (mtch (tyinsts,insts) (f,g)) (t, u)
clasohm@0
   275
      | _ => raise MATCH
paulson@2725
   276
  in mtch([],[]) (eta_contract pat, eta_contract obj) end;
nipkow@678
   277
nipkow@678
   278
nipkow@678
   279
fun match_bind(itms,binders,ixn,is,t) =
nipkow@678
   280
  let val js = loose_bnos t
nipkow@678
   281
  in if null is
nipkow@678
   282
     then if null js then (ixn,t)::itms else raise MATCH
berghofe@1576
   283
     else if js subset_int is
nipkow@678
   284
          then let val t' = if downto0(is,length binders - 1) then t
nipkow@678
   285
                            else mapbnd (idx is) t
nipkow@678
   286
               in (ixn, mkabs(binders,is,t')) :: itms end
nipkow@678
   287
          else raise MATCH
nipkow@678
   288
  end;
nipkow@678
   289
nipkow@678
   290
(*Tests whether 2 terms are alpha/eta-convertible and have same type.
nipkow@678
   291
  Note that Consts and Vars may have more than one type.*)
nipkow@678
   292
infix aeconv;
nipkow@678
   293
fun (Const(a,T)) aeconv (Const(b,U)) = a=b  andalso  T=U
nipkow@678
   294
  | (Free(a,T))  aeconv (Free(b,U))  = a=b  andalso  T=U
nipkow@678
   295
  | (Var(v,T))   aeconv (Var(w,U))   = v=w  andalso  T=U
nipkow@678
   296
  | (Bound i)    aeconv (Bound j)    = i=j
nipkow@678
   297
  | (Abs(_,T,t)) aeconv (Abs(_,U,u)) = (t aeconv u)  andalso  T=U
nipkow@678
   298
  | (Abs(_,T,t)) aeconv u            = t aeconv ((incr u)$Bound(0))
nipkow@678
   299
  | t            aeconv (Abs(_,U,u)) = ((incr t)$Bound(0)) aeconv u
nipkow@678
   300
  | (f$t)        aeconv (g$u)        = (f aeconv g)  andalso (t aeconv u)
nipkow@678
   301
  | _ aeconv _                       =  false;
nipkow@678
   302
nipkow@678
   303
nipkow@678
   304
fun match tsg (po as (pat,obj)) =
nipkow@678
   305
let
nipkow@678
   306
nipkow@678
   307
fun typ_match args = Type.typ_match tsg args
nipkow@678
   308
                     handle Type.TYPE_MATCH => raise MATCH;
nipkow@678
   309
nipkow@678
   310
(* Pre: pat and obj have same type *)
nipkow@678
   311
fun mtch binders (env as (iTs,itms),(pat,obj)) =
nipkow@678
   312
      case pat of
nipkow@678
   313
        Abs(ns,Ts,ts) =>
nipkow@678
   314
          (case obj of
nipkow@678
   315
             Abs(nt,Tt,tt) => mtch ((nt,Tt)::binders) (env,(ts,tt))
nipkow@678
   316
           | _ => let val Tt = typ_subst_TVars iTs Ts
nipkow@678
   317
                  in mtch((ns,Tt)::binders)(env,(ts,(incr obj)$Bound(0))) end)
nipkow@678
   318
      | _ => (case obj of
nipkow@678
   319
                Abs(nt,Tt,tt) =>
nipkow@678
   320
                  mtch((nt,Tt)::binders)(env,((incr pat)$Bound(0),tt))
nipkow@678
   321
              | _ => cases(binders,env,pat,obj))
nipkow@678
   322
nipkow@678
   323
and cases(binders,env as (iTs,itms),pat,obj) =
nipkow@678
   324
      let val (ph,pargs) = strip_comb pat
nipkow@678
   325
          fun rigrig1(iTs,oargs) =
nipkow@678
   326
                foldl (mtch binders) ((iTs,itms), pargs~~oargs)
nipkow@678
   327
          fun rigrig2((a,Ta),(b,Tb),oargs) =
nipkow@678
   328
                if a<> b then raise MATCH
nipkow@678
   329
                else rigrig1(typ_match(iTs,(Ta,Tb)), oargs)
nipkow@678
   330
      in case ph of
nipkow@678
   331
           Var(ixn,_) =>
nipkow@678
   332
             let val is = ints_of pargs
berghofe@1576
   333
             in case assoc_string_int(itms,ixn) of
nipkow@678
   334
                  None => (iTs,match_bind(itms,binders,ixn,is,obj))
nipkow@678
   335
                | Some u => if obj aeconv (red u is []) then env
nipkow@678
   336
                            else raise MATCH
nipkow@678
   337
             end
nipkow@678
   338
         | _ =>
nipkow@678
   339
             let val (oh,oargs) = strip_comb obj
nipkow@678
   340
             in case (ph,oh) of
nipkow@678
   341
                  (Const c,Const d) => rigrig2(c,d,oargs)
nipkow@678
   342
                | (Free f,Free g)   => rigrig2(f,g,oargs)
nipkow@678
   343
                | (Bound i,Bound j) => if i<>j then raise MATCH
nipkow@678
   344
                                       else rigrig1(iTs,oargs)
nipkow@678
   345
                | (Abs _, _)        => raise Pattern
nipkow@678
   346
                | (_, Abs _)        => raise Pattern
nipkow@678
   347
                | _                 => raise MATCH
nipkow@678
   348
             end
nipkow@678
   349
      end;
nipkow@678
   350
nipkow@678
   351
val pT = fastype_of pat
nipkow@678
   352
and oT = fastype_of obj
nipkow@678
   353
val iTs = typ_match ([],(pT,oT))
nipkow@678
   354
nipkow@678
   355
in mtch [] ((iTs,[]), po)
nipkow@678
   356
   handle Pattern => fomatch tsg po
nipkow@678
   357
end;
clasohm@0
   358
clasohm@0
   359
(*Predicate: does the pattern match the object?*)
nipkow@678
   360
fun matches tsig po = (match tsig po; true) handle MATCH => false;
clasohm@0
   361
clasohm@0
   362
end;