

umin (>"_"+x,x>):->;
umin (>"-"+x,x>):->;
umin (>x,"_"+x>):.

int of float (>INT+y,INT>):.

INT ::@ i num (x>).

i num (x>): !0123456789! +(x>), ->;
i num ("0">): ^!! * (x>). 

TRUE  :: "True".
FALSE :: "False".

condition (>TRUE,>then part,>else part, then part>): ->;
condition (>FALSE,>then part,>else part, else part>):->;
condition (>x,>then part,>else part, VErr*STRING*"*** Bool required ">):.

%TEX     
\subsubsection{Transform indices VBuiltin {\tt "[]"}}
%
index (>"-"+x,>y,VErr*STRING*msg>): ->, 
   where (>"*** Negative index : -"+x, msg>);
index (>"_"+x,>y,VErr*STRING*msg>): ->, 
   where (>"*** Negative index : -"+x, msg>);
index (>nr,>VList*LIST*args, list index>): ->,
   list index (>nr,>args, list index>);
index (>nr,>cons, cons index>):
   where (>cons,VComp*_>), ->,
   cons index (>nr,>cons, cons index>);
index (>nr,>cons, VInd*cons*I NUM *nr>):.
   

list index (>nr,>VList*LIST*empty, VErr*STRING*msg>): ->, 
   where (>"*** Index out of range:", msg>);
list index (>"0",>a*r, a>): ->; 
list index (>MINUS 1,>a*r, x>): 
  list index(>MINUS 1,>r,x>), ->;
list index (>nr,>el,VInd*el*I NUM *nr>):. 

cons index (>nr,>VList*LIST*empty, VErr*STRING*msg>): 
   where (>"*** Index out of range ", msg>), ->;
cons index (>"0",>VComp*a*r, a>): ->;
cons index (>MINUS 1,>VComp*a*r, x>): ->,
  cons index (>MINUS 1,>r,x>);
cons index (>nr,>el,VInd*el*I NUM *nr>):.


slice (>lw,>upb,>VList*LIST* els ,slice>): ->,
  skip lwb list elements (>lw, >els,>els, n els>, rest lw>),
  more list slice  (>rest lw,>lw, >upb, >n els, slice>);
slice (>lw,>upb,>cons, slice>):
   where (>cons,VComp*_>), ->,
   skip lwb cons elements (>lw, >cons, ncons>, rest lw>),
  more cons slice  (>rest lw,>lw, >upb, >n cons, slice>);
slice (>lw,>upb,>nocons, VSlice*no cons*lw'*upb'>):
   where (>I NUM*lw, lw'>),
   where (>I NUM*upb, upb'>).

more list slice (>"0",>lw, >upb,>n els, slice>): ->,
    compute (>upb + "-"+lw+"+1", nr>),
    list slice (> nr, >n els, slice>);
more list slice (>rest,>lw, >upb,>r, slice>):
    compute (>upb + "-"+lw+"+"+rest, nu>),
    where (>VSlice*r*l*u,slice>),
    where (>I NUM*rest, l>),
    where (>I NUM*nu, u>).

more cons slice (>"0",>lw, >upb,>n els, slice>): ->,
    compute (>upb + "-"+lw+"+1", nr>),
    cons slice (> nr, >n els, slice>);
more cons slice (>rest,>lw, >upb,>r, slice>):
    compute (>upb + "-"+lw+"+"+rest, nu>),
    where (>VSlice*r*l*u,slice>),
    where (>I NUM*rest, l>),
    where (>I NUM*nu, u>).

list slice (>"-"+x, >els , empty>): ->;
list slice (>"0", >els , empty>): ->;
list slice (>MINUS 1, >e*ee , VComp*e*slice>): 
   list slice (>MINUS 1, >ee, slice>), ->;
list slice (>MINUS 1,>r, slice >): 
    where (>VSlice*r*zero*upb,slice>),
    where (>I NUM*"0", zero>),
    where (>I NUM*MINUS 1, upb>).
    
     
skip lwb list elements (>"0", >prev,>els, els>, "0">): ->;
skip lwb list elements (>MINUS 1, >prev,>cur , n els>, rest>):
     where (>cur, el*r>),
     skip lwb list elements (>MINUS 1,>prev,>r, n els>, rest>), ->;
skip lwb list elements (>rest , >prev, >empty , prev>, rest>):.

skip lwb cons elements (>"0",>els, els>, "0">): ->;
skip lwb cons elements (>MINUS 1,>VComp*a*r, x>, rest>):  ->,
  skip lwb cons elements (>MINUS 1,>r,x>, rest>);
skip lwb cons elements (>rest,>last el, last el>,rest>):. 

cons slice (>"-"+x, >els ,  VList*LIST*empty>): ->;
cons slice (>"0",>els, VList*LIST*empty>): ->;
cons slice (>MINUS 1,>VComp*a*r,  VComp*a*slice>): 
  cons slice (>MINUS 1,>r,slice>), ->;
cons slice (>MINUS 1,>r, slice >): 
    where (>VSlice*r*zero*upb,slice>), 
    where (>INUM*"0", zero>),
    where (>INUM*MINUS 1, upb>).
