Skip to content

Exploring the Language 1

netrium edited this page Mar 24, 2012 · 10 revisions

Increasing the Complexity

Through the power of combinators, the simple language elements be used to construct highly complex contracts with relative ease. Note, that unless otherwise specified, all Decision Tree visualisations have the acquisition time set to 2011-01-01 00:00:00.

Joining two contracts

The following sample contract extends the top contract by adding a payment (give) of one EUR to the existing receipt of one GBP at the time of acquisition.

contract = one (Financial gbp cash Nothing) `and` give (one (Financial eur cash Nothing))

The Syntax Tree is now:

Syntax Tree

The Decision Tree now shows this as follows:

Decision Tree

Going beyond One

contract = scale 1000 (one (Financial gbp cash Nothing))

The scale keyword acts as a multiplier. It is used to multiply the child contract by a factor. In the above example, the contract acquirer now receives 1,000 GBP at the moment of contract acquisition.

The Syntax Tree for this contract:

Decision Tree

The Decision Tree now shows:

Decision Tree

scale can be added to a contract many times. There are times that this can be useful, especially when working with multiple independent external observables.

contract = scale 2000 (scale 1000 (one (Financial gbp cash Nothing)))

This now shows as:

Syntax Tree

The Decision Tree - which is the result of execution of the contract as of 1/1/2011 - now shows:

Decision Tree

Introducing Time into a contract

contract = when (at (date 2013 1 1)) (one (Financial gbp cash Nothing))

The above contract, as long as it is acquired before 1 January 2013, will deliver one GBP to the acquirer at exactly 00:00:00 on 1 January 2013.

The Syntax Tree:

Syntax Tree

The Decision Tree:

Decision Tree

Introducing Optionality

The or keyword allows the contract to make a decision. Decisions must always be supplied - with a timestamp that they were made at - in the Observable database. This can be used to support options and other path dependent contracts. or is always accompanied by a label, which allows the decision to be addressed at runtime.

contract =  or "foo" (one (Financial gbp cash Nothing)) Zero

In the above example, the decision named 'foo' must be supplied by the contract acquirer. If they select to take the option 'foo', they will receive one GBP, otherwise Zero.

The Syntax Tree:

Syntax Tree

The Decision Tree:

Decision Tree

Next

The role of Time

Samples

A suite of samples is available here.

Clone this wiki locally