Task

Create a function that returns the maximum value in a provided set of values,

where the number of values may not be known until run-time.




 
bundle agent __main__
{
  vars:
      "number_of_list_elements"
        int => randomint( "0", 100 ),
        unless => isvariable( "$(this.promiser)" );
 
      "idx"
        slist => expandrange( "[0-$(number_of_list_elements)]", 1 ),
        unless => isvariable( "$(this.promiser)" );
 
      "number[$(idx)]"
        int => randomint( "0", "100" ),
        unless => isvariable( "$(this.promiser)" );
 
      "numbers" slist => sort( getvalues( number ), int );
 
  methods:
      "Get the greatest value"
        usebundle => greatest_value( @(numbers) ),
        useresult => "returned";
 
  reports:
      "'$(returned[max])' is the largest number in $(with)"
        with => join( ",", numbers );
 
 
}
bundle agent greatest_value(list_of_values)
{
   reports:
      "$(with)"
        with => max( list_of_values, int ),
        bundle_return_value_index => "max";
}
 