Changeset 4032


Ignore:
Timestamp:
Nov 12, 2008, 7:45:34 PM (12 years ago)
Author:
yura
Message:
  • Simplification.
File:
1 edited

Legend:

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

    r4031 r4032  
    195195IsElem e t.item e t.item;
    196196
     197$public $func? IsNotElem e.list t.item = ;
     198IsNotElem e.list t.item = # <IsElem e.list t.item>;
     199
    197200$public $func Foldl t.func (e.value) e.list = e.value;
    198201Foldl t.func (e.value) e.list =
     
    218221
    219222$public $func? All t.func e.list = ;
    220 All t.func e.list =
    221   <SimplifyFunction t.func> :: s.func e.arg,
    222   e.list $iter {
    223     e.list : t.head e.tail = <Apply.Apply s.func e.arg t.head> :: e, e.tail;
    224   } :: e.list, e.list : /*empty*/;
     223All t.func e.list = <SimplifyFunction t.func> :: s.func e.arg,
     224  { e.list : e t.item e, # { <Apply.Apply s.func e.arg t.item> :: e; } = $fail;; };
    225225
    226226$public $func? Any t.func e.list = ;
    227 Any t.func e.list = # \{
    228   <SimplifyFunction t.func> :: s.func e.arg,
    229   e.list $iter {
    230     e.list : t.head e.tail = # \{ <Apply.Apply s.func e.arg t.head > :: e; }, e.tail;
    231   } :: e.list, e.list : /*empty*/;
    232 };
     227Any t.func e.list = <SimplifyFunction t.func> :: s.func e.arg,
     228  e.list : e t.item e, <Apply.Apply s.func e.arg t.item> :: e;
    233229
    234230$public $func Subtract (e.list1) (e.list2) = e.list;
    235 Subtract (e.list1) (e.list2) =
    236   /*empty*/ (e.list1) $iter {
    237     e.list1 : term e.rest,
    238       {
    239         e.list2 : e term e =  e.not (e.rest);
    240         = e.not term (e.rest);
    241       };
    242   } ::  e.not (e.list1), e.list1 : /*empty*/ =
    243   e.not;
     231Subtract (e.list1) (e.list2) = <Filter (&IsNotElem e.list2) e.list1>;
     232
     233$public $func Intersect (e.list1) (e.list2) = e.list;
     234Intersect (e.list1) (e.list2) = <Filter (&IsElem e.list2) e.list1>;
     235
     236$public $func Union (e.list1) (e.list2) = e.list;
     237Union (e.list1) (e.list2) = e.list1 <Subtract (e.list2) (e.list1)>;
    244238
    245239//$const Concat = (&Map &Deparen_Term);
Note: See TracChangeset for help on using the changeset viewer.