Reference


Top     Installation     Introduction     Samples     Tutorial     Reference     Release Notes


Rule Functions

These are functions that can be used in rules.

Some functions can only be used in rule sets running from Excel worksheets (the normal case), but will not work if exported for use in other environments, although in some cases (such as ASK and MSGBOX) support can be provided for those environments. Ask technical support for details on specific functions.

General

ASK( prompt )* — Displays an input box and returns the value the user entered. (Not for export to non-Excel environments.)

ASK( prompt, title, default ) — Displays an input box and returns the value the user entered, and uses the specified title and default value in the displayed input box. (Not for export to non-Excel environments.)

DEBUGPRINT( string ) — For use when developing VBA code for use with ARulesXL. The argument is displayed in the VBA Immediate window. (Not for export to non-Excel environments.)

EVALUATE( string_excel_function ) — The argument is a string representing an Excel function call. It can be dynamically created using the ARulesXL string concatenation operator. The return value is whatever the Excel function returns. Note that this feature can also be used to call user defined functions written in VBA, allowing for ARulesXL rules to get data from VBA. (Not for export to non-Excel environments.)

EXISTS( property ) — Returns true if there is a definition, either as data or as a rule, for the fact. Otherwise returns false.

IS_KNOWN( property ) — Returns true if the value for the fact is already known, otherwise returns false. This can be used to determine if a fact value was input from a query or not.

IS_RULESET( name ) — Returns true if the name is a rule set.

MSGBOX( string ) — Displays a message box with the string as a message. (Not for export to non-Excel environments.)

ONETIME( goal ) — Calls the goal just once. This is useful within FINDALL for pattern-matching rules that only need to be called once.

QUIT( message ) — Ends whatever query was happening with a message of your choice, which will appear as an error message result for the query..

RANGE( property ) — For the fact that originated from an RArray() or RCell(), returns the spreadsheet cell, or list of cells where that property was loaded from the spreadsheet. (Not for export to non-Excel environments.)

Arrays & Lists

Arrays and lists are the same, and are both represented as: [element1, element2, ..., elementN]

AFTER( list, value ) — Returns the value after specified value in a sorted array or list. The specified value does not have to exist in the list. For example, AFTER(.names, "M") will return the next name in the listing starting with M, or if there are none, the name after M in the alphabet. Use NEXT for non-sorted lists.

APPEND( list, list ) — Appends the second list to the first, and returns the results.

BEFORE( list, value ) — Returns the value before the specified value in a sorted array or list. The specified value does not have to exist in the list. For example, BEFORE(.names, "M") will return the prior name in the listing starting with L, or if there are none, the name before M in the alphabet. Use PRIOR for non-sorted lists.

COLLECT variable FOREACH generator WHERE test — The basic looping function that can be specified as a statement or as a function (see next entry). It creates a collection of instances of the variable. The loop is driven by the generator function, and for each pass through the loop the test is applied to see what the value of the variable is. Example:

items = [car, train, lion, tiger, boat].
is_animal[?x] = "true" WHEN ?x = member( [lion, tiger, bear] ).
animals = COLLECT ?x FOREACH ?x = MEMBER( items ) WHERE is_animal[?x] = true

COLLECT( variable, generator, test ) — COLLECT in a function form so it can be nested in other list functions: ex. SORT( COLLECT( ?item, ?item = MEMBER( items ), is_ok[?item] ) )

CONCATENATE( list_of_lists) — Concatenates a list of lists into a single list. ex. CONCATENATE( [ [1,2], [3,4], [5,6] ] ) = [1, 2, 3, 4, 5, 6]

COUNT( list ) — Returns the number of elements i the list.

FINDALL( variable, criteria ) — Finds all the values in an array or list that meet the specified criteria.

FIRST( list ) — Returns the first value in the array.

INDEX( property, argument ) — Can be used as a generator for COLLECT(). It generates each index for the given property. This is useful for getting row or column headings from tables read in using RArray(), or from arrays of facts in rules that have arguments.

cost[widget] = 3
cost[gizmo] = 4
cost[thing] = 5
order = [thing, gizmo]
total_cost = SUM( COLLECT( ?cost, ?item = INDEX(cost, 1), (?item = MEMBER( order ) AND ?cost = cost[?item] ) ) )

This example would be better using MEMBER( order ) as a generator, but it wouldn't have illustrated the use of INDEX() or compound conditions in the test.

ITEM_AT( list, offset ) — Returns the item at the 'offset' position in the list.

LAST( list ) — Returns the last value in the array.

MEMBER( list ) — Returns a member of a list. It is intended for use in findall, returning all of the members of a list for processing in the findall.

NEXT( list, item ) — Returns the next item in the list, after the specified item. If the list is sorted, use AFTER instead.

PERMUTE( list ) — Returns a permutation of the list. When used in a FINDALL, will return all of the permutations of a list.

PRIOR( list, item) — Returns the prior item in the list, after the specified item. If the list is sorted, use BEFORE instead.

RANGE( table_element ) — Returns the cell or range from which a table element was taken using RArray(). Intended for use from VBA to allow the annotation of worksheets.

REVERSE( list ) — Returns a reversed copy of the list.

REMOVE_DUPLICATES( list ) — Returns a copy of the list with duplicates removed.

SORT( list ) — Returns a sorted copy of the list.

SUM( number_list ) — Returns the sum of the numbers in the list.

Sets

A set is a sorted list without duplicates.

SET( list ) — Converts the list to a set, that is a list which is sorted with no duplicates, and returns that set.

UNION( list, list ) — Returns the union of the two lists, which is the set of all elements that are in either list. For example: UNION([ a, b, c], [b, c, d]) = [ a, b, c, d]

INTERSECTION( list, list ) — Returns the intersection of the two lists, which is the set of all elements that are in both lists. For example: INTERSECTION( [a, b, c], [b, c, d]) = [ b, c ].

DIFFERENCE( list, list ) — Returns the difference of the two lists, which is the set of all elements that are in the first list but not in the second. For example: DIFFERENCE( [a, b, c], [b, c, d] ) = [ a ].

IS_SUBSET( list, list ) — Returns true if the first list is a subset of the second. ex. IS_SUBSET( [a, b, c], [b, c, d] ) = false.

Date/Time

See the section on Using Dates and Times in Rules for more details.

DAY( date ) — Returns the day number when date is a valid date.

DAYS_BETWEEN( start_date, end_date ) — Returns the number of days between the two dates. Note that this is different than the result from using the arithmetic operator, -, which returns an interval with years, months and days.

MAKE_DATE( year, month, day ) — Creates a date fact with the specified date.

MAKE_DATETIME( year, month, day, hour, minute, second ) — Creates a date fact with the specified date and time.

MONTH( date ) — Returns the month number when date is a valid date.

WEEKDAY( date ) — Returns the week day name (Sunday, Monday, ...) when date is a valid date.

YEAR( date ) — Returns the year when date is a valid date.

Arithmetic

MAXIMUM( list ) — Returns the largest value in the list.

MINIMUM( list ) — Returns the smallest value in the list.

Open in New Window to Print


Copyright ©2005-7 Amzi! inc. All Rights Reserved.
ARulesXL and Amzi! are trademarks or registered trademarks of Amzi!
Microsoft and Excel are trademarks or registered trademarks of Microsoft Corporation.