next up previous contents
Next: User-defined Answer Formats Up: Functions Previous: Overview

Examples for Usage of Functions

  1. The following query counts the number of instances of Class:
    COUNT[Class/class]

    The result will look like

    119 in COUNT[Class / class]
    end
  2. This query sums up the salaries of an Employee:
    SUM_Attribute[Bill/objname,Employee!salary/attrcat]

    Unfortunately, the result is returned everytime as a real number, even if the input numbers were integers.

    2.5001000000000e+04 in SUM_Attribute[Bill / objname, Employee!salary / attrcat]
    end

    You can use this function also in query class to compute the value of a ``computed_attribute'':

    QueryClass EmployeesWithSumSalaries isA Employee with
    computed_attribute
        sumsalary : Real
    constraint
        c: $ (~sumsalary in SUM_Attribute[this/objname,Employee!salary/attrcat]) $
    end
  3. Complex computations can be made by using multiple functions in a row. This query returns the percentage of query classes wrt. the total number of classes.
    QueryClass PercentageOfQueryClasses isA Real with
    constraint
        c: $ exists i1,i2/Integer r/Real
        (i1 in COUNT[QueryClass/class]) and (i2 in COUNT[Class/class]) and
        (r in DIV[i1/r1,i2/r2]) and (this in MULT[100/r1,r/r2]) $
    end


ConceptBase Team