home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / ifp / part01 / fproot / demo / PowerSet < prev    next >
Encoding:
Text File  |  1987-07-05  |  415 b   |  25 lines

  1. (*
  2.  * PowerSet
  3.  *
  4.  * This function generates all subsets of a given set.  Sets are 
  5.  * represented as sequences of distinct elements.
  6.  *
  7.  * Examples:
  8.  *
  9.  *      <> : PowerSet -> <<>>
  10.  *
  11.  *      <a b c> : PowerSet -> <<a,b,c>,<a,b>,<a,c>,<a>,<b,c>,<b>,<c>,<>>
  12.  *)
  13.  
  14. DEF PowerSet AS
  15.    IF null THEN [id] 
  16.    ELSE 
  17.       [1, tl | PowerSet] |
  18.       [
  19.          distl | EACH apndl END,
  20.      2 
  21.       ] 
  22.       | cat 
  23.    END;
  24.  
  25.