table digest with rules ...

Prev Next

Function Names

table digest with rules, table digest with rules ignore case

Description

This function combines the lookup strategy from table lookup with rules() with the data integration features of table digest().

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,  Leg count,  Surface,    Special Skills   },
        { Parrot,    small,    50,        flying,    2,          feathers,   immitates voices },
        { 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,  Leg count,  Surface, Special Skills  },
            { '*',      ':mod([.],40)=0','*', '*',        '*',     '*'   }, // Speed divisible by 40 -> Owl
            { small,    '20..30',  '*',       '*',        Hair,    '*'   }, // Dog Cat Fox
            { '*',      '<1',      '*',       '*',        '*',     '*'   } } );

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

  // Data integration process: Overwrite movement in target table, Add animal name to 'It's ...' and note double speed.

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

  echo("Target table after lookup (", count[], " items found):");
  table list( target );

Output

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

Target table after lookup (5 items found):
    0 : Size  | Speed          | Movement | Leg count | Surface | Special Skills | Animal      | Average Speed | Top Speed
    1 : *     | :mod([.],40)=0 | *        | *         | *       | *              | Owl         | 80            | 80       
    2 : small | 20..30         | *        | *         | Hair    | *              | Dog Cat Fox | 25            | 30       
    3 : *     | <1             | *        | *         | *       | *              | Worm        | 0.01          | 0.01     

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

See also

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