Ignore:
Timestamp:
Oct 24, 2008, 2:46:34 PM (12 years ago)
Author:
yura
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/refal/refal/plus/List2.rf

    r3995 r3996  
    1010    t.func : (t.func1 e.arg1) = t.func1 e.arg1 e.arg;
    1111  } :: t.func e.arg, t.func : s.funcRef =
    12   s.funcRef;
     12  s.funcRef e.arg;
    1313
    1414$public $func? Apply t.func e.arg = e.res;
     
    5151  (e.true_list) (e.false_list);
    5252
    53 $public $func IsElem e.list t.item = ;
     53$public $func? IsElem e.list t.item = ;
    5454IsElem e t.item e t.item;
    5555
     
    113113  () e.list $iter {
    114114    e.list : e.before e.sep e.after = (e.ll (e.before)) e.after;
    115     (e.ll (e.list));
     115    = (e.ll (e.list));
    116116  } :: (e.ll) e.list, e.list : /*empty*/ =
    117117  e.ll;
    118 
    119 $func Paren_Term term = (term);
    120 Paren_Term term = (term);
    121118
    122119$func ConcatHelp t.term = e.expr;
     
    129126Concat e.lists = <Map &ConcatHelp e.lists>;
    130127
    131 //Nub e.expr = <NubBy &EqTerms e.expr>;
    132 //
    133 //NubBy s.eqTerms e.expr =
    134 //  e.expr () $iter {
    135 //    e.expr : term e.rest, {
    136 //      <Any s.eqTerms term (e.selected)> = e.rest (e.selected);
    137 //      e.rest (e.selected (term));
    138 //    };
    139 //  } :: e.expr (e.selected),
    140 //  e.expr : /*empty*/ =
    141 //  <Concat e.selected>;
    142 //
     128$public $func? EqTerms t.term t.term = ;
     129EqTerms t1 t1;
     130
     131$public $func Nub e.list = e.list;
     132Nub e.list = <NubBy &EqTerms e.list>;
     133
     134$public $func NubBy t.eqTerms e.list = e.list;
     135NubBy t.eqTerms e.list =
     136  () e.list $iter {
     137    e.list : t.head e.tail, {
     138      <Any (t.eqTerms t.head) e.new_list> = (e.new_list) e.tail;
     139      = (e.new_list (t.head)) e.tail;
     140    };
     141  } :: (e.new_list) e.list, e.list : /*empty*/ =
     142  e.new_list;
     143
    143144//Replicate s.n e.expr =
    144145//  s.n /*e.list*/ $iter
     
    147148//  <Le (s.n) (0)> =
    148149//  e.list;
    149 //
    150 //
    151 //
    152150
    153151$func QSort_Split t.num e.list = (e.list) (e.list);
    154152QSort_Split t.num e.list,
    155   () () (e.list) $iter {
     153  () () e.list $iter {
    156154    e.list : t.head e.tail, {
    157       <Le (t.head) (t.num)>,
    158         (e.smaller t.head) (e.greater) (e.tail);
    159       (e.smaller) (e.greater t.head) (e.tail);
     155      <Le (t.head) (t.num)> = (e.smaller t.head) (e.greater) e.tail;
     156      = (e.smaller) (e.greater t.head) e.tail;
    160157    };
    161   } :: (e.smaller) (e.greater) (e.list),
    162   e.list : /*empty*/,
     158  } :: (e.smaller) (e.greater) e.list, e.list : /*empty*/ =
    163159  (e.smaller) (e.greater);
    164160
     
    170166};
    171167
    172 //SortBy s.cmpTerms e.list =
    173 //  <Length e.list> :: s.len,
    174 //  {
    175 //    <Le (s.len) (1)> = e.list;
    176 //    <Div s.len 2> :: s.k =
    177 //      <Merge s.cmpTerms (<SortBy s.cmpTerms <Left 0 s.k e.list>>) (<SortBy s.cmpTerms <Middle s.k 0 e.list>>)>;
    178 //  };
    179 //
    180 //$func Merge s.cmpTerms (e.left) (e.right) = e.merged_list;
    181 //Merge s.cmpTerms (e.left) (e.right) =
    182 //  (e.left) (e.right) $iter {
    183 //    e.left : t.l e.left_rest, e.right : t.r e.right_rest = {
    184 //      <Apply s.cmpTerms t.l t.r> : '<' = (e.left_rest) (e.right) e.merged t.l;
    185 //      = (e.left) (e.right_rest) e.merged t.r;
    186 //    };
    187 //  } :: (e.left) (e.right) e.merged,
    188 //  \{
    189 //    e.left  : /*empty*/ = e.merged e.right;
    190 //    e.right : /*empty*/ = e.merged e.left;
    191 //  };
    192 //
    193 //Sort e.list = <SortBy &CompareTerms e.list>;
     168$public $func CompareTerms t.term t.term = s.cmp;
     169CompareTerms t.term1 t.term2 = <Compare (t.term1) (t.term2)>;
     170
     171$public $func Sort e.list = e.list;
     172Sort e.list = <SortBy &CompareTerms e.list>;
     173
     174$public $func SortBy t.cmpTerms e.list = e.list;
     175SortBy t.cmpTerms e.list =
     176  <Length e.list> :: s.len,
     177  {
     178    <Le (s.len) (1)> = e.list;
     179    <Div s.len 2> :: s.k =
     180      <Merge t.cmpTerms (<SortBy t.cmpTerms <Left 0 s.k e.list>>) (<SortBy t.cmpTerms <Middle s.k 0 e.list>>)>;
     181  };
     182
     183$func Merge t.cmpTerms (e.left) (e.right) = e.merged_list;
     184Merge t.cmpTerms (e.left) (e.right) =
     185  (e.left) (e.right) $iter {
     186    e.left : t.l e.left_rest, e.right : t.r e.right_rest = {
     187      <Apply t.cmpTerms t.l t.r> : '<' = e.merged t.l (e.left_rest) (e.right);
     188      = e.merged t.r (e.left) (e.right_rest);
     189    };
     190  } :: e.merged (e.left) (e.right),
     191  \{
     192    e.left  : /*empty*/ = e.merged e.right;
     193    e.right : /*empty*/ = e.merged e.left;
     194  };
Note: See TracChangeset for help on using the changeset viewer.