Defining functions

Defining Rules

Functions can be thought of as microservices written in the rule language and are defined like this:

Define rules with nontrivial rule conditions like this:

(, ..., ) =

Example: square(*n) = *n * *n

Variables in functions: The let expression As function definitions are based on expressions rather than action sequences, we cannot put an assignment directly inside an expression. For example, the following is not a valid function definition: quad(*n) = *t = *n * *n; *t * *t

To solve this problem, the let expression provides scoped values in an expression. The general syntax for the let expression is: let in

For example: quad(*n) = let *t = *n * *n in *t * *t

The variable on the left hand side of the assignment in the let expression is a let­bound variable. The scope of such a variable is within the let expression. A let bound variable should not be reassigned inside the let expression.

(, ..., ) { on() { } }

The rule condition can be skipped for rules with trivial or non­existent conditions: (, ..., ) { }

A rule can have multiple conditional expressions: (, ..., ) { on() { } ... on() { } }

Generating and Capturing Errors In a rule, we can also prevent the rule from failing when a microservice fails: errorcode(msi)

The errormsg microservice captures the error message, allows further processing of the error message, and avoids the default logging of the error message, like so: errormsg(msi, *msg)

In a rule, the fail() and failmsg() microservices can be used to generate errors. fail(errorcode) generates an error with an error code.

Example:

Here the type name defined is nat. The type parameter list is empty. If the type fail(-1) parameter list is empty, we may omit it. There are two data constructors. The first failmsg(, ) constructor "zero" has type "nat," which generates an error with an error code and an means that "zero" is a nullary constructor error message. of nat. We use "zero" to represent "0". The second constructor "succ" has type Example: "nat ­> nat" which means that "succ" is failmsg(-1, "this is an error message") unary constructor of nat. We use "succ" to represent the successor. With these two constructors we can represent all The msiExit microservice is similar to failmsg: natural numbers: zero, succ(zero), msiExit("-1", "msi") succ(succ(zero)).

Inductive Data Types

Pattern matching

The features discussed in this section are currently under development!

If a data type has more than one data structure, then the "match" expression is useful:

An inductive data type is a data type for values that can be defined inductively, i.e. more complex values can be constructed from simpler values using constructors. General syntax: data [ ( ) ] = | : ... | :

For example, a data type that represents the natural numbers can be defined as data nat = | zero : nat | succ : nat -> nat

match with | => ... | =>

For example, given the nat data type we defined earlier, we can define the following function using the match expression: add(*x, *y) = match *x with | zero => *y | succ(*z) => succ(add(*z, *y))

For another example, given the "tree" data type we defined earlier, we can define the following function size(*t) = match *t with | empty => 0 | node(*v, *l, *r) => 1 + size(*l) + size(*r)

Defining functions Defining Rules Generating and Capturing ... - GitHub

language and are defined like this: (, ... ... generates an error with an error code and an error message. ... node(*v, *l, *r) => 1 + size(*l) + size(*r).

98KB Sizes 1 Downloads 302 Views

Recommend Documents

Defining new approximations of belief functions by means of ...
representations are sought, i.e. by means of belief functions with a restricted number of focal elements. The second drawback is the lack of intuitive significance for a belief function with several focal elements of different cardinality. As explain

Counting with generating functions in MAXIMA - GitHub
In this paper we describe implementations of two counting methods which are based on generating func- ... Pólya theory [2] is an important counting method when some objects that are ...... [9] http://www.tcs.hut.fi/Software/bliss/index.html. 19.

Defining and Testing EMR Usability - MOspace
Jun 8, 2009 - from initial costs and lost productivity during EMR implementation, is lack of ... We provide samples of objective, repeatable and cost-efficient.

Defining the scientific method - Nature
documents on the internet. This generated quite a response from the scientific com- munity with California Institute of Technology physicist ... funds the work and the biologists who conduct it want results that will materially impact the quality of

Defining and Testing EMR Usability - MOspace
Jun 8, 2009 - “meaningful use” will require that efficiency and usability be ... Usability evaluation is far broader than the simple process of measuring user satisfaction. ..... An important means of reducing density is viewing data at a summary

Defining the scientific method - Nature
amounts of data does not dictate that biology should be data- driven. In a return to ... method works for Google because language has simple rules and low ...

Defining Principles - Joyner.pdf
once said, “The defining moment of Unitarian Universalism is always now.” Now is the time to. engage in changing the First Principle, for the moment is always ...

Defining the scientific method - Nature
accepted definition of the scientific method, the answer would be a qualified no. ... sible to obtain massive amounts of 'omics' data on a variety of biological ...

Defining a Nation
Apr 5, 2007 - it exuded permanence and a continuity of administrative rule which ... business; British presence in India was, after all, predicated on the East ..... city plan took shape around Raisina Hill, to the southwest of Old Delhi.

Bressler Defining Theory, Criticism, & Literature.pdf
Sign in. Page. 1. /. 22. Loading… Page 1 of 22. Page 1 of 22. Page 2 of 22. Page 2 of 22. Page 3 of 22. Page 3 of 22. Bressler Defining Theory, Criticism, ...

Defining the Nonprofit Sector: Israel
This is one in a series of Working Papers produced under the Johns Hopkins .... historical review into three main periods: (1) The Diaspora era, (2) the pre-State years ..... definition of “income from trade or business dealings” is very ambiguou

Uveal melanoma - Chromosomal aberrations defining ...
Data were then exported to. Microsoft Excel for completion of calculations. ...... (30) Parrella P, Fazio VM, Gallo AP, Sidransky D, Merbs SL. Fine mapping of ...