Basic Concepts
From KynetxDocs
Contents |
Lexicon
The following lexicon contains words and concepts from KNS that are important to understand to create KRL rulesets and to interpret the analytics associated with them.
- action - the effects that a rule has on the calling page are called actions. A rule may have more than one action. Depending on the structure of the consequent, all of the actions or one chosen at random may be taken.
- active - see rule state.
- caller - see calling page.
- callback - a rule may have an associated callback that tracks whether a rule succeeded or failed based on the actions of the user. Callbacks are not associated with rulesets or actions. They are only associated with rules.
- calling page - the page that a KNS ruleset is being evaluated against. This is sometimes referred to as the caller or the page.
- consequent - the statement of the effect a rule will take. A consequent is made up of one or more actions. When the consequent is evaluated, a Javascript program is generated and sent to the browser to affect the calling page.
- endpoint - The method in which a Kynetx app is deployed. The endpoint is responsible for initiating the call to KNS and mediating the interaction with the client
- evaluation - see ruleset evaluation.
- fire - a selected rule is evaluated to determine if the predicate in its premise is true. If it is, the rule is said to have "fired." When a rule fires, it's consequent is evaluated.
- inactive - see rule state.
- page - see calling page.
- premise - the predicate phrase that is evaluated to determine whether the rule fires. When a rule fires, the consequent is evaluated. The premise may be empty. In that case the rule always fires when it is selected.
- rule - a statement of the actions that should be taken on a particular set of calling pages whenever the antecedent is true. Each rule has a rule name that should be unique within the ruleset.
- rule state - a rule can be active, inactive, or test. By marking a rule inactive the rule can be turned off without deleting it from the ruleset or commenting it out. A rule in a test state will only be evaluated if mode in the evaluation is test.
- ruleset - A collection of rules in the Kynetx Rule Language. Rulesets are uniquely identified by a ruleset ID, or RID.
- ruleset evaluation - A ruleset can be evaluated using the KNS API. When the ruleset is evaluated, each active rules are selected using the selector specification, the antecedents of the selected rules are evaluated and if true, the rule is fired. For billing purposes, a ruleset is only considered to have been evaluated when one or more rules in the ruleset fire.
- ruleset id - also RID, the ruleset ID is the unique identifier for a ruleset.
- selected - Each rule contains a selector specification in the form of a regular expression that is matched against the URL of the calling page. The selected rules are typically a small subset of the total number of rules in the ruleset. Because the selector specification is a regular expression it can represent a class of URLs or pages to match.
- test - see rule state.
- transaction ID - the transaction ID or TXN_ID is a unique identifier for a ruleset evaluation. Each callback includes the name of the rule in which it was defined. That information, along with the TXN_ID associates rule evaluations and callbacks over time since a callback could take place long after a rule has fired.
Program Structure
A KRL program consists of one or more rulesets that comprise multiple rules along with other blocks that affect the entire ruleset.
Multiple rulesets are linked together to form a single program using a dispatch block.
Variable Structure and Regions
An identifier can name a location where a value can be stored. An identifier that names a location is called a variable and is said to be bound to that location. The set of all visible bindings in effect at some point in a program is known as the environment in effect at that point. The value stored in the location to which a variable is bound is called the variable's value.
Expression and statement types that create new locations and bind variables to those locations are called binding constructs. Select statements and declarations can bind variables to values.
KRL is a statically scoped language. To each place where an identifier is bound in a program there corresponds a region of the program text within which the binding is visible. The region is determined by the particular programatic context where the binding is made.
A rule is a binding scope and all bindings constructed within a rule are visible throughout the rule, but not in other rules.
Some bindings, like those made in a global declaration are visible globally throughout the ruleset. Variables set as part of the rule selection process are considered to have global scope.
Page environment parameters (the parameters to the GET HTTP call that initiates execution) that are not namespaced with the RID are visible to all rulesets executing at in that call.
Rule Evaluation Order
Rules are guaranteed to exectute in the order that they are listed in the ruleset. When a ruleset is evaluated, every rule that is selected is executed in the order that they are listed in the ruleset. There is no looping at the ruleset level--for any given event, the ruleset is executed exactly once.
