table digest with rules once ...

Prev Next

Function Names

table digest with rules once, table digest with rules ignore case once

Description

This function combines the benefits of table digest with rules() and table integrate once(). Every entry in the look-up table is referenced only once.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

6 - 9 (For parameter description and return values: see table expand() )

Examples



       table initialize( animals,
               { { Name,      Size,     Speed,     Movement,  Legs,  Surface,    Special Skills   },
                 { Parrot,    small,    50,        flying,    2,     feathers,   immitates voices },
                 { Donkey,    medium,   28,        walking,   4,     hair,       agriculture use  },
                 { Dog,       small,    30,        walking,   4,     hair,       sense of smell   },
                 { Cat,       small,    20,        walking,   4,     hair,       night vision     },
                 { Fox,       small,    25,        walking,   4,     hair,       relatively smart },
                 { Owl,       small,    80,        flying,    2,     feathers,   night vision     },
                 { Worm,      tiny,     0.01,      crawling,  0,     mucous skin,unclear          },
                 { Whale,     huge,     30,        swimming,  0,     skin,       relatively smart } } );

       headers[] = [animals:..,0]-{Name};


       table initialize( target,
                       { { Size,     Speed,     Movement,  Legs, Surface, Special Skills   },
                         { '*',      ':mod([.],40)=0','*', '*',  '*',     '*'              }, // Speed divisible by 40 -> Owl
                         { small,    '20..30',  '*',       '*',  Hair,    '*'              }, // Dog, Cat, Fox
                         { small,    '20..30',  '*',       '*',  Hair,    '*'              }, // No match (items already found)
                         { '*',      '20..30',  '*',       '*',  '*',     '*'              } } ); // Donkey and Whale only

       count[] = table digest with rules once ignore case ( target, headers[],  {Legs, Animal, Avg Speed, Top Speed},
                         animals, headers[], {Legs, Name,   Speed, Speed},   { overwrite, append with space, average, max }, true, Counter );

       echo("List of animals with counted lookups:");
       table list( animals );

       echo("Note: Dog/Cat/Fox can be found only once.  Row 4: Donkey and Whale found (Dog/Cat/Fox already taken)");
       echo("Target table after lookup (", count[], " items found):");
       table list( target );

Output

List of animals with counted lookups:
    0 : Name   | Size   | Speed | Movement | Legs | Surface     | Special Skills   | Counter
    1 : Parrot | small  | 50    | flying   | 2    | feathers    | immitates voices |        
    2 : Donkey | medium | 28    | walking  | 4    | hair        | agriculture use  | 1      
    3 : Dog    | small  | 30    | walking  | 4    | hair        | sense of smell   | 1      
    4 : Cat    | small  | 20    | walking  | 4    | hair        | night vision     | 1      
    5 : Fox    | small  | 25    | walking  | 4    | hair        | relatively smart | 1      
    6 : Owl    | small  | 80    | flying   | 2    | feathers    | night vision     | 1      
    7 : Worm   | tiny   | 0.01  | crawling | 0    | mucous skin | unclear          |        
    8 : Whale  | huge   | 30    | swimming | 0    | skin        | relatively smart | 1      

Note: Dog/Cat/Fox can be found only once.  Row 4: Donkey and Whale found (Dog/Cat/Fox already taken)
Target table after lookup (6 items found):
    0 : Size  | Speed          | Movement | Legs | Surface | Special Skills | Animal       | Avg Speed | Top Speed
    1 : *     | :mod([.],40)=0 | *        | 2    | *       | *              | Owl          | 80        | 80       
    2 : small | 20..30         | *        | 4    | Hair    | *              | Dog Cat Fox  | 25        | 30       
    3 : small | 20..30         | *        | *    | Hair    | *              |              |           |          
    4 : *     | 20..30         | *        | 0    | *       | *              | Donkey Whale | 29        | 30       

Try it yourself: Open LIB_Function_table_digest_with_rules_once.b4p in B4P_Examples.zip. Decompress before use.

See also

table digest with rules
table digest
table lookup with rules once
table integrate with rules once
table expand with rules once