blob: b6faa580f86a2c45fdf2711860105c2a782e56e3 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.10">
<meta name="author" content="Copyright (c) 2010, 2020 Contributors to the Eclipse Foundation">
<link rel="icon" type="image/png" href="favicon.png">
<title>Chi documentation (Incubation)</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<style>
/* Asciidoctor default stylesheet | MIT License | https://asciidoctor.org */
/* Uncomment @import statement to use as custom stylesheet */
/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700";*/
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}
audio,video{display:inline-block}
audio:not([controls]){display:none;height:0}
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
a{background:none}
a:focus{outline:thin dotted}
a:active,a:hover{outline:0}
h1{font-size:2em;margin:.67em 0}
abbr[title]{border-bottom:1px dotted}
b,strong{font-weight:bold}
dfn{font-style:italic}
hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}
mark{background:#ff0;color:#000}
code,kbd,pre,samp{font-family:monospace;font-size:1em}
pre{white-space:pre-wrap}
q{quotes:"\201C" "\201D" "\2018" "\2019"}
small{font-size:80%}
sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
sup{top:-.5em}
sub{bottom:-.25em}
img{border:0}
svg:not(:root){overflow:hidden}
figure{margin:0}
fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
legend{border:0;padding:0}
button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
button,input{line-height:normal}
button,select{text-transform:none}
button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}
button[disabled],html input[disabled]{cursor:default}
input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}
button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
textarea{overflow:auto;vertical-align:top}
table{border-collapse:collapse;border-spacing:0}
*,*::before,*::after{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}
html,body{font-size:100%}
body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;font-weight:400;font-style:normal;line-height:1;position:relative;cursor:auto;tab-size:4;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}
a:hover{cursor:pointer}
img,object,embed{max-width:100%;height:auto}
object,embed{height:100%}
img{-ms-interpolation-mode:bicubic}
.left{float:left!important}
.right{float:right!important}
.text-left{text-align:left!important}
.text-right{text-align:right!important}
.text-center{text-align:center!important}
.text-justify{text-align:justify!important}
.hide{display:none}
img,object,svg{display:inline-block;vertical-align:middle}
textarea{height:auto;min-height:50px}
select{width:100%}
.center{margin-left:auto;margin-right:auto}
.stretch{width:100%}
.subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em}
div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0;direction:ltr}
a{color:#2156a5;text-decoration:underline;line-height:inherit}
a:hover,a:focus{color:#1d4b8f}
a img{border:0}
p{font-family:inherit;font-weight:400;font-size:1em;line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
p aside{font-size:.875em;line-height:1.35;font-style:italic}
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
h1{font-size:2.125em}
h2{font-size:1.6875em}
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
h4,h5{font-size:1.125em}
h6{font-size:1em}
hr{border:solid #dddddf;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em;height:0}
em,i{font-style:italic;line-height:inherit}
strong,b{font-weight:bold;line-height:inherit}
small{font-size:60%;line-height:inherit}
code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)}
ul,ol,dl{font-size:1em;line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
ul,ol{margin-left:1.5em}
ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0;font-size:1em}
ul.square li ul,ul.circle li ul,ul.disc li ul{list-style:inherit}
ul.square{list-style-type:square}
ul.circle{list-style-type:circle}
ul.disc{list-style-type:disc}
ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
dl dt{margin-bottom:.3125em;font-weight:bold}
dl dd{margin-bottom:1.25em}
abbr,acronym{text-transform:uppercase;font-size:90%;color:rgba(0,0,0,.8);border-bottom:1px dotted #ddd;cursor:help}
abbr{text-transform:none}
blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
blockquote cite{display:block;font-size:.9375em;color:rgba(0,0,0,.6)}
blockquote cite::before{content:"\2014 \0020"}
blockquote cite a,blockquote cite a:visited{color:rgba(0,0,0,.6)}
blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
@media screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
h1{font-size:2.75em}
h2{font-size:2.3125em}
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
h4{font-size:1.4375em}}
table{background:#fff;margin-bottom:1.25em;border:solid 1px #dedede}
table thead,table tfoot{background:#f7f8f7}
table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
table tr.even,table tr.alt{background:#f8f8f7}
table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{display:table-cell;line-height:1.6}
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
.clearfix::before,.clearfix::after,.float-group::before,.float-group::after{content:" ";display:table}
.clearfix::after,.float-group::after{clear:both}
:not(pre):not([class^=L])>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background:#f7f7f8;-webkit-border-radius:4px;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed;word-wrap:break-word}
:not(pre)>code.nobreak{word-wrap:normal}
:not(pre)>code.nowrap{white-space:nowrap}
pre{color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;line-height:1.45;text-rendering:optimizeSpeed}
pre code,pre pre{color:inherit;font-size:inherit;line-height:inherit}
pre>code{display:block}
pre.nowrap,pre.nowrap pre{white-space:pre;word-wrap:normal}
em em{font-style:normal}
strong strong{font-weight:400}
.keyseq{color:rgba(51,51,51,.8)}
kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background:#f7f7f7;border:1px solid #ccc;-webkit-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em white inset;box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em #fff inset;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap}
.keyseq kbd:first-child{margin-left:0}
.keyseq kbd:last-child{margin-right:0}
.menuseq,.menuref{color:#000}
.menuseq b:not(.caret),.menuref{font-weight:inherit}
.menuseq{word-spacing:-.02em}
.menuseq b.caret{font-size:1.25em;line-height:.8}
.menuseq i.caret{font-weight:bold;text-align:center;width:.45em}
b.button::before,b.button::after{position:relative;top:-1px;font-weight:400}
b.button::before{content:"[";padding:0 3px 0 2px}
b.button::after{content:"]";padding:0 2px 0 3px}
p a>code:hover{color:rgba(0,0,0,.9)}
#header,#content,#footnotes,#footer{width:100%;margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
#header::before,#header::after,#content::before,#content::after,#footnotes::before,#footnotes::after,#footer::before,#footer::after{content:" ";display:table}
#header::after,#content::after,#footnotes::after,#footer::after{clear:both}
#content{margin-top:1.25em}
#content::before{content:none}
#header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0}
#header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #dddddf}
#header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px}
#header .details{border-bottom:1px solid #dddddf;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:-ms-flexbox;display:-webkit-flex;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap}
#header .details span:first-child{margin-left:-.125em}
#header .details span.email a{color:rgba(0,0,0,.85)}
#header .details br{display:none}
#header .details br+span::before{content:"\00a0\2013\00a0"}
#header .details br+span.author::before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
#header .details br+span#revremark::before{content:"\00a0|\00a0"}
#header #revnumber{text-transform:capitalize}
#header #revnumber::after{content:"\00a0"}
#content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #dddddf;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
#toc{border-bottom:1px solid #e7e7e9;padding-bottom:.5em}
#toc>ul{margin-left:.125em}
#toc ul.sectlevel0>li>a{font-style:italic}
#toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
#toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
#toc li{line-height:1.3334;margin-top:.3334em}
#toc a{text-decoration:none}
#toc a:active{text-decoration:underline}
#toctitle{color:#7a2518;font-size:1.2em}
@media screen and (min-width:768px){#toctitle{font-size:1.375em}
body.toc2{padding-left:15em;padding-right:0}
#toc.toc2{margin-top:0!important;background:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #e7e7e9;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
#toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em}
#toc.toc2>ul{font-size:.9em;margin-bottom:0}
#toc.toc2 ul ul{margin-left:0;padding-left:1em}
#toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
body.toc2.toc-right{padding-left:0;padding-right:15em}
body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #e7e7e9;left:auto;right:0}}
@media screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
#toc.toc2{width:20em}
#toc.toc2 #toctitle{font-size:1.375em}
#toc.toc2>ul{font-size:.95em}
#toc.toc2 ul ul{padding-left:1.25em}
body.toc2.toc-right{padding-left:0;padding-right:20em}}
#content #toc{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
#content #toc>:first-child{margin-top:0}
#content #toc>:last-child{margin-bottom:0}
#footer{max-width:100%;background:rgba(0,0,0,.8);padding:1.25em}
#footer-text{color:rgba(255,255,255,.8);line-height:1.44}
#content{margin-bottom:.625em}
.sect1{padding-bottom:.625em}
@media screen and (min-width:768px){#content{margin-bottom:1.25em}
.sect1{padding-bottom:1.25em}}
.sect1:last-child{padding-bottom:0}
.sect1+.sect1{border-top:1px solid #e7e7e9}
#content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
#content h1>a.anchor::before,h2>a.anchor::before,h3>a.anchor::before,#toctitle>a.anchor::before,.sidebarblock>.content>.title>a.anchor::before,h4>a.anchor::before,h5>a.anchor::before,h6>a.anchor::before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
#content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
#content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none}
#content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
details,.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
details>summary:first-of-type{cursor:pointer;display:list-item;outline:none;margin-bottom:.75em}
.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic}
table.tableblock.fit-content>caption.title{white-space:nowrap;width:0}
.paragraph.lead>p,#preamble>.sectionbody>[class="paragraph"]:first-of-type p{font-size:1.21875em;line-height:1.6;color:rgba(0,0,0,.85)}
table.tableblock #preamble>.sectionbody>[class="paragraph"]:first-of-type p{font-size:inherit}
.admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
.admonitionblock>table td.icon{text-align:center;width:80px}
.admonitionblock>table td.icon img{max-width:none}
.admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
.admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #dddddf;color:rgba(0,0,0,.6)}
.admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
.exampleblock>.content{border-style:solid;border-width:1px;border-color:#e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;-webkit-border-radius:4px;border-radius:4px}
.exampleblock>.content>:first-child{margin-top:0}
.exampleblock>.content>:last-child{margin-bottom:0}
.sidebarblock{border-style:solid;border-width:1px;border-color:#dbdbd6;margin-bottom:1.25em;padding:1.25em;background:#f3f3f2;-webkit-border-radius:4px;border-radius:4px}
.sidebarblock>:first-child{margin-top:0}
.sidebarblock>:last-child{margin-bottom:0}
.sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
.literalblock pre,.listingblock>.content>pre{-webkit-border-radius:4px;border-radius:4px;word-wrap:break-word;overflow-x:auto;padding:1em;font-size:.8125em}
@media screen and (min-width:768px){.literalblock pre,.listingblock>.content>pre{font-size:.90625em}}
@media screen and (min-width:1280px){.literalblock pre,.listingblock>.content>pre{font-size:1em}}
.literalblock pre,.listingblock>.content>pre:not(.highlight),.listingblock>.content>pre[class="highlight"],.listingblock>.content>pre[class^="highlight "]{background:#f7f7f8}
.literalblock.output pre{color:#f7f7f8;background:rgba(0,0,0,.9)}
.listingblock>.content{position:relative}
.listingblock code[data-lang]::before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:inherit;opacity:.5}
.listingblock:hover code[data-lang]::before{display:block}
.listingblock.terminal pre .command::before{content:attr(data-prompt);padding-right:.5em;color:inherit;opacity:.5}
.listingblock.terminal pre .command:not([data-prompt])::before{content:"$"}
.listingblock pre.highlightjs{padding:0}
.listingblock pre.highlightjs>code{padding:1em;-webkit-border-radius:4px;border-radius:4px}
.listingblock pre.prettyprint{border-width:0}
.prettyprint{background:#f7f7f8}
pre.prettyprint .linenums{line-height:1.45;margin-left:2em}
pre.prettyprint li{background:none;list-style-type:inherit;padding-left:0}
pre.prettyprint li code[data-lang]::before{opacity:1}
pre.prettyprint li:not(:first-child) code[data-lang]::before{display:none}
table.linenotable{border-collapse:separate;border:0;margin-bottom:0;background:none}
table.linenotable td[class]{color:inherit;vertical-align:top;padding:0;line-height:inherit;white-space:normal}
table.linenotable td.code{padding-left:.75em}
table.linenotable td.linenos{border-right:1px solid currentColor;opacity:.35;padding-right:.5em}
pre.pygments .lineno{border-right:1px solid currentColor;opacity:.35;display:inline-block;margin-right:.75em}
pre.pygments .lineno::before{content:"";margin-right:-.125em}
.quoteblock{margin:0 1em 1.25em 1.5em;display:table}
.quoteblock:not(.excerpt)>.title{margin-left:-1.5em;margin-bottom:.75em}
.quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
.quoteblock blockquote{margin:0;padding:0;border:0}
.quoteblock blockquote::before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
.quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
.quoteblock .attribution{margin-top:.75em;margin-right:.5ex;text-align:right}
.verseblock{margin:0 1em 1.25em}
.verseblock pre{font-family:"Open Sans","DejaVu Sans",sans;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
.verseblock pre strong{font-weight:400}
.verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
.quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
.quoteblock .attribution br,.verseblock .attribution br{display:none}
.quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)}
.quoteblock.abstract blockquote::before,.quoteblock.excerpt blockquote::before,.quoteblock .quoteblock blockquote::before{display:none}
.quoteblock.abstract blockquote,.quoteblock.abstract p,.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{line-height:1.6;word-spacing:0}
.quoteblock.abstract{margin:0 1em 1.25em;display:block}
.quoteblock.abstract>.title{margin:0 0 .375em;font-size:1.15em;text-align:center}
.quoteblock.excerpt>blockquote,.quoteblock .quoteblock{padding:0 0 .25em 1em;border-left:.25em solid #dddddf}
.quoteblock.excerpt,.quoteblock .quoteblock{margin-left:0}
.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{color:inherit;font-size:1.0625rem}
.quoteblock.excerpt .attribution,.quoteblock .quoteblock .attribution{color:inherit;text-align:left;margin-right:0}
table.tableblock{max-width:100%;border-collapse:separate}
p.tableblock:last-child{margin-bottom:0}
td.tableblock>.content>:last-child{margin-bottom:-1.25em}
td.tableblock>.content>:last-child.sidebarblock{margin-bottom:0}
table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
table.grid-all>thead>tr>.tableblock,table.grid-all>tbody>tr>.tableblock{border-width:0 1px 1px 0}
table.grid-all>tfoot>tr>.tableblock{border-width:1px 1px 0 0}
table.grid-cols>*>tr>.tableblock{border-width:0 1px 0 0}
table.grid-rows>thead>tr>.tableblock,table.grid-rows>tbody>tr>.tableblock{border-width:0 0 1px}
table.grid-rows>tfoot>tr>.tableblock{border-width:1px 0 0}
table.grid-all>*>tr>.tableblock:last-child,table.grid-cols>*>tr>.tableblock:last-child{border-right-width:0}
table.grid-all>tbody>tr:last-child>.tableblock,table.grid-all>thead:last-child>tr>.tableblock,table.grid-rows>tbody>tr:last-child>.tableblock,table.grid-rows>thead:last-child>tr>.tableblock{border-bottom-width:0}
table.frame-all{border-width:1px}
table.frame-sides{border-width:0 1px}
table.frame-topbot,table.frame-ends{border-width:1px 0}
table.stripes-all tr,table.stripes-odd tr:nth-of-type(odd),table.stripes-even tr:nth-of-type(even),table.stripes-hover tr:hover{background:#f8f8f7}
th.halign-left,td.halign-left{text-align:left}
th.halign-right,td.halign-right{text-align:right}
th.halign-center,td.halign-center{text-align:center}
th.valign-top,td.valign-top{vertical-align:top}
th.valign-bottom,td.valign-bottom{vertical-align:bottom}
th.valign-middle,td.valign-middle{vertical-align:middle}
table thead th,table tfoot th{font-weight:bold}
tbody tr th{display:table-cell;line-height:1.6;background:#f7f8f7}
tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
p.tableblock>code:only-child{background:none;padding:0}
p.tableblock{font-size:1em}
ol{margin-left:1.75em}
ul li ol{margin-left:1.5em}
dl dd{margin-left:1.125em}
dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none}
ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em}
ul.unstyled,ol.unstyled{margin-left:0}
ul.checklist{margin-left:.625em}
ul.checklist li>p:first-child>.fa-square-o:first-child,ul.checklist li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em}
ul.checklist li>p:first-child>input[type="checkbox"]:first-child{margin-right:.25em}
ul.inline{display:-ms-flexbox;display:-webkit-box;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap;list-style:none;margin:0 0 .625em -1.25em}
ul.inline>li{margin-left:1.25em}
.unstyled dl dt{font-weight:400;font-style:normal}
ol.arabic{list-style-type:decimal}
ol.decimal{list-style-type:decimal-leading-zero}
ol.loweralpha{list-style-type:lower-alpha}
ol.upperalpha{list-style-type:upper-alpha}
ol.lowerroman{list-style-type:lower-roman}
ol.upperroman{list-style-type:upper-roman}
ol.lowergreek{list-style-type:lower-greek}
.hdlist>table,.colist>table{border:0;background:none}
.hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em}
td.hdlist1{font-weight:bold;padding-bottom:1.25em}
.literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
.colist td:not([class]):first-child{padding:.4em .75em 0;line-height:1;vertical-align:top}
.colist td:not([class]):first-child img{max-width:none}
.colist td:not([class]):last-child{padding:.25em 0}
.thumb,.th{line-height:0;display:inline-block;border:solid 4px #fff;-webkit-box-shadow:0 0 0 1px #ddd;box-shadow:0 0 0 1px #ddd}
.imageblock.left{margin:.25em .625em 1.25em 0}
.imageblock.right{margin:.25em 0 1.25em .625em}
.imageblock>.title{margin-bottom:0}
.imageblock.thumb,.imageblock.th{border-width:6px}
.imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
.image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
.image.left{margin-right:.625em}
.image.right{margin-left:.625em}
a.image{text-decoration:none;display:inline-block}
a.image object{pointer-events:none}
sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super}
sup.footnote a,sup.footnoteref a{text-decoration:none}
sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline}
#footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
#footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0}
#footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em}
#footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em}
#footnotes .footnote:last-of-type{margin-bottom:0}
#content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
.gist .file-data>table{border:0;background:#fff;width:100%;margin-bottom:0}
.gist .file-data>table td.line-data{width:99%}
div.unbreakable{page-break-inside:avoid}
.big{font-size:larger}
.small{font-size:smaller}
.underline{text-decoration:underline}
.overline{text-decoration:overline}
.line-through{text-decoration:line-through}
.aqua{color:#00bfbf}
.aqua-background{background:#00fafa}
.black{color:#000}
.black-background{background:#000}
.blue{color:#0000bf}
.blue-background{background:#0000fa}
.fuchsia{color:#bf00bf}
.fuchsia-background{background:#fa00fa}
.gray{color:#606060}
.gray-background{background:#7d7d7d}
.green{color:#006000}
.green-background{background:#007d00}
.lime{color:#00bf00}
.lime-background{background:#00fa00}
.maroon{color:#600000}
.maroon-background{background:#7d0000}
.navy{color:#000060}
.navy-background{background:#00007d}
.olive{color:#606000}
.olive-background{background:#7d7d00}
.purple{color:#600060}
.purple-background{background:#7d007d}
.red{color:#bf0000}
.red-background{background:#fa0000}
.silver{color:#909090}
.silver-background{background:#bcbcbc}
.teal{color:#006060}
.teal-background{background:#007d7d}
.white{color:#bfbfbf}
.white-background{background:#fafafa}
.yellow{color:#bfbf00}
.yellow-background{background:#fafa00}
span.icon>.fa{cursor:default}
a span.icon>.fa{cursor:inherit}
.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
.admonitionblock td.icon .icon-note::before{content:"\f05a";color:#19407c}
.admonitionblock td.icon .icon-tip::before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
.admonitionblock td.icon .icon-warning::before{content:"\f071";color:#bf6900}
.admonitionblock td.icon .icon-caution::before{content:"\f06d";color:#bf3400}
.admonitionblock td.icon .icon-important::before{content:"\f06a";color:#bf0000}
.conum[data-value]{display:inline-block;color:#fff!important;background:rgba(0,0,0,.8);-webkit-border-radius:100px;border-radius:100px;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
.conum[data-value] *{color:#fff!important}
.conum[data-value]+b{display:none}
.conum[data-value]::after{content:attr(data-value)}
pre .conum[data-value]{position:relative;top:-.125em}
b.conum *{color:inherit!important}
.conum:not([data-value]):empty{display:none}
dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility}
h1,h2,p,td.content,span.alt{letter-spacing:-.01em}
p strong,td.content strong,div.footnote strong{letter-spacing:-.005em}
p,blockquote,dt,td.content,span.alt{font-size:1.0625rem}
p{margin-bottom:1.25rem}
.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
.exampleblock>.content{background:#fffef7;border-color:#e0e0dc;-webkit-box-shadow:0 1px 4px #e0e0dc;box-shadow:0 1px 4px #e0e0dc}
.print-only{display:none!important}
@page{margin:1.25cm .75cm}
@media print{*{-webkit-box-shadow:none!important;box-shadow:none!important;text-shadow:none!important}
html{font-size:80%}
a{color:inherit!important;text-decoration:underline!important}
a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
a[href^="http:"]:not(.bare)::after,a[href^="https:"]:not(.bare)::after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
abbr[title]::after{content:" (" attr(title) ")"}
pre,blockquote,tr,img,object,svg{page-break-inside:avoid}
thead{display:table-header-group}
svg{max-width:100%}
p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
#toc,.sidebarblock,.exampleblock>.content{background:none!important}
#toc{border-bottom:1px solid #dddddf!important;padding-bottom:0!important}
body.book #header{text-align:center}
body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em}
body.book #header .details{border:0!important;display:block;padding:0!important}
body.book #header .details span:first-child{margin-left:0!important}
body.book #header .details br{display:block}
body.book #header .details br+span::before{content:none!important}
body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
.listingblock code[data-lang]::before{display:block}
#footer{padding:0 .9375em}
.hide-on-print{display:none!important}
.print-only{display:block!important}
.hide-for-print{display:none!important}
.show-for-print{display:inherit!important}}
@media print,amzn-kf8{#header>h1:first-child{margin-top:1.25rem}
.sect1{padding:0!important}
.sect1+.sect1{border:0}
#footer{background:none}
#footer-text{color:rgba(0,0,0,.6);font-size:.9em}}
@media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!--
Copyright (c) 2010, 2020 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
This program and the accompanying materials are made available under the terms
of the MIT License which is available at https://opensource.org/licenses/MIT
SPDX-License-Identifier: MIT
-->
<style>
.menu, .submenu, .menuitem, .menuref {
background-color: Menu;
}
.button {
border: 1px solid ButtonFace;
/*
Styling too similar to a real button is considered bad practice, see https://github.com/asciidoctor/asciidoctor/issues/1881#issuecomment-250702085
border: 2px outset ButtonFace;
background-color: ButtonFace;
*/
padding-left: 0.5ex;
padding-right: 0.5ex;
font-weight: normal;
font-family: "Segoe UI","Open Sans","DejaVu Sans",sans-serif;
white-space: nowrap;
}
.button:before {
content: none !important;
}
.button:after {
content: none !important;
}
#footer-text, #footer-text a {
color: rgba(255,255,255,.8)
}
</style>
</head>
<body class="book toc2 toc-left">
<div id="header">
<h1>Chi documentation (Incubation)</h1>
<div class="details">
<span id="author" class="author">Copyright (c) 2010, 2020 Contributors to the Eclipse Foundation</span><br>
<span id="revnumber">version 0.1.0.20210126-175926</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#tut-chapter-chi-tutorial">Chi Tutorial</a>
<ul class="sectlevel2">
<li><a href="#tut-chapter-introduction">Introduction</a></li>
<li><a href="#tut-chapter-data-types">Data types</a></li>
<li><a href="#tut-chapter-statements">Statements</a></li>
<li><a href="#tut-chapter-functions">Functions</a></li>
<li><a href="#tut-chapter-input-and-output">Input and output</a></li>
<li><a href="#tut-chapter-stochastic-behavior">Modeling stochastic behavior</a></li>
<li><a href="#tut-chapter-processes">Processes</a></li>
<li><a href="#tut-chapter-channels">Channels</a></li>
<li><a href="#tut-chapter-buffers">Buffers</a></li>
<li><a href="#tut-chapter-servers-with-time">Servers with time</a></li>
<li><a href="#tut-chapter-conveyors">Conveyors</a></li>
<li><a href="#tut-chapter-simulation-and-experiments">Simulations and experiments</a></li>
<li><a href="#tut-chapter-svg-visualization">SVG visualization</a></li>
<li><a href="#tut-chapter-svg-example">SVG visualization example</a></li>
</ul>
</li>
<li><a href="#ref-chapter-reference-manual">Chi Reference Manual</a>
<ul class="sectlevel2">
<li><a href="#ref-chapter-global-definitions">Global definitions</a></li>
<li><a href="#ref-chapter-statements">Statements</a></li>
<li><a href="#ref-chapter-expressions">Expressions</a></li>
<li><a href="#ref-chapter-standard-library">Standard library functions</a></li>
<li><a href="#ref-chapter-distributions">Distributions</a></li>
<li><a href="#ref-chapter-types">Types</a></li>
<li><a href="#ref-chapter-lexical-syntax">Lexical syntax</a></li>
<li><a href="#ref-chapter-migration">Model migration</a></li>
<li><a href="#ref-chapter-svg-visualization">SVG visualization</a></li>
</ul>
</li>
<li><a href="#tool-chapter-tool-manual">Chi Tool Manual</a>
<ul class="sectlevel2">
<li><a href="#tool-chapter-software-operation">Software operation</a></li>
<li><a href="#tool-chapter-command-line">Command line options</a></li>
</ul>
</li>
<li><a href="#release-notes-chapter-index">Chi release notes</a>
<ul class="sectlevel2">
<li><a href="#version-0-1-unreleased">Version 0.1 (unreleased)</a></li>
</ul>
</li>
<li><a href="#legal-chapter-index">Legal</a></li>
</ul>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Chi is a modeling language for describing and analyzing performance of
discrete event systems by means of simulation.
It uses a process-based view, and uses synchronous point-to-point
communication between processes. A process is written as an imperative
program, with a syntax much inspired by the well-known Python language.</p>
</div>
<div class="paragraph">
<p>Chi is one of the tools of the
<a href="https://eclipse.org/escet">Eclipse ESCET&#8482; project</a>.</p>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The Eclipse ESCET project, including the Chi language and toolset,
is currently in the
<a href="https://wiki.eclipse.org/Development_Resources/Process_Guidelines/What_is_Incubation">Incubation Phase</a>.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="./eclipse-incubation.png" alt="eclipse incubation" width="300"></span></p>
</div>
</td>
</tr>
</table>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
You can <a href="eclipse-escet-incubation-chi-manual.pdf">download this manual</a>
as a PDF as well.
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Tutorial</dt>
<dd>
<p>The <a href="#tut-chapter-chi-tutorial">Chi Tutorial</a>
teaches the Chi language, and its use in modeling and simulating systems
to answer your performance questions.</p>
<div class="paragraph">
<p>Some interesting topics are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Basics (<a href="#tut-chapter-data-types">Data types</a>, <a href="#tut-chapter-statements">Statements</a>,
<a href="#tut-chapter-stochastic-behavior">Modeling stochastic behavior</a>)</p>
</li>
<li>
<p>Programming (<a href="#tut-chapter-processes">Processes</a>, <a href="#tut-chapter-channels">Channels</a>)</p>
</li>
<li>
<p>Modeling (<a href="#tut-chapter-buffers">Buffers</a>, <a href="#tut-chapter-servers-with-time">Servers with time</a>,
<a href="#tut-chapter-conveyors">Conveyors</a>)</p>
</li>
</ul>
</div>
</dd>
<dt class="hdlist1">Reference manual</dt>
<dd>
<p>The <a href="#ref-chapter-reference-manual">Chi Reference Manual</a>
describes the Chi language in full detail, for example the top level language
elements or all statements. It also contains a list with all standard library
functions and a list with all distribution functions.</p>
<div class="paragraph">
<p>Some interesting topics are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#ref-chapter-global-definitions">Global definitions</a> (Top level language elements)</p>
</li>
<li>
<p><a href="#ref-chapter-standard-library">Standard library functions</a> (Standard library functions)</p>
</li>
<li>
<p><a href="#ref-chapter-distributions">Distributions</a> (Available distributions)</p>
</li>
</ul>
</div>
</dd>
<dt class="hdlist1">Tool manual</dt>
<dd>
<p>The <a href="#tool-chapter-tool-manual">Tool manual</a>
describes the Chi simulator software.
Use of the software to create and simulate Chi programs is also explained.</p>
</dd>
<dt class="hdlist1">Release notes</dt>
<dd>
<p>The <a href="#release-notes-chapter-index">Release notes</a> provides information on
all Chi releases.</p>
</dd>
<dt class="hdlist1">Legal</dt>
<dd>
<p>See <a href="#legal-chapter-index">Legal</a> for copyright and licensing information.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect1">
<h2 id="tut-chapter-chi-tutorial">Chi Tutorial</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This manual explains using the Chi modeling language.</p>
</div>
<div class="paragraph">
<p><em>Topics</em></p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#tut-chapter-introduction">Introduction</a> (global description of the aims of the language)</p>
</li>
<li>
<p><em>Basics</em>: Elementary knowledge needed for writing and understanding Chi
programs. <em>Start here to learn the language!</em></p>
<div class="ulist">
<ul>
<li>
<p><a href="#tut-chapter-data-types">Data types</a> (explanation of all kinds of data and their
operations)</p>
</li>
<li>
<p><a href="#tut-chapter-statements">Statements</a> (available process statements)</p>
</li>
<li>
<p><a href="#tut-chapter-functions">Functions</a> (how to use functions)</p>
</li>
<li>
<p><a href="#tut-chapter-input-and-output">Input and output</a> (reading/writing files, displaying output)</p>
</li>
</ul>
</div>
</li>
<li>
<p><em>Programming</em>: How to specify parallel executing processes using the Chi
language.</p>
<div class="ulist">
<ul>
<li>
<p><a href="#tut-chapter-stochastic-behavior">Modeling stochastic behavior</a> (how to model varying behavior)</p>
</li>
<li>
<p><a href="#tut-chapter-processes">Processes</a> (creating and running processes)</p>
</li>
<li>
<p><a href="#tut-chapter-channels">Channels</a> (connecting processes with each other)</p>
</li>
</ul>
</div>
</li>
<li>
<p><em>Modeling</em>: Modeling a real system with Chi.</p>
<div class="ulist">
<ul>
<li>
<p><a href="#tut-chapter-buffers">Buffers</a> (modeling temporary storage of items)</p>
</li>
<li>
<p><a href="#tut-chapter-servers-with-time">Servers</a> (modeling machines)</p>
</li>
<li>
<p><a href="#tut-chapter-conveyors">Conveyors</a> (modeling conveyor belts)</p>
</li>
<li>
<p><a href="#tut-chapter-simulation-and-experiments">Experiments</a> (performing simulation experiments)</p>
</li>
</ul>
</div>
</li>
<li>
<p><em>Visualization</em>: Making an animated graphical display of a system with the
Chi simulator.</p>
<div class="ulist">
<ul>
<li>
<p><a href="#tut-chapter-svg-visualization">SVG visualization</a> (how to attach an SVG visualization)</p>
</li>
<li>
<p><a href="#tut-chapter-svg-example">SVG example</a> (an SVG example)</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<div class="sect2">
<h3 id="tut-chapter-introduction">Introduction</h3>
<div class="paragraph">
<p>The topic is modeling of the operation of (manufacturing) systems, e.g.
semiconductor factories, assembly and packaging lines, car manufacturing
plants, steel foundries, metal processing shops, beer breweries, health care
systems, warehouses, order-picking systems.
For a proper functioning of these systems, these systems are controlled by
operators and electronic devices, e.g. computers.</p>
</div>
<div class="paragraph">
<p>During the design process, engineers make use of (analytical) mathematical
models, e.g. algebra and probability theory, to get answers about the
operation of the system.
For complex systems, (numerical) mathematical models are used, and computers
perform simulation experiments, to analyze the operation of the system.
Simulation studies give answers to questions like:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>What is the throughput of the system?</p>
</li>
<li>
<p>What is the effect of set-up time in a machine?</p>
</li>
<li>
<p>How will the batch size of an order influence the flow time of the
product-items?</p>
</li>
<li>
<p>What is the effect of more surgeons in a hospital?</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>
The operation of a system can be described, e.g. in terms of or operating
processes.</p>
</div>
<div class="paragraph">
<p>An example of a system with parallel operating processes is a manufacturing
line, with a number of manufacturing machines, where product-items go from
machine to machine.
A surgery room in a hospital is a system where patients are treated by teams
using medical equipment and sterile materials.
A biological system can be described by a number of parallel processes, where,
e.g. processes transform sugars into water and carbon-dioxide producing
energy.
In all these examples, processes operate in parallel to complete a task, and
to achieve a goal.
Concurrency is the dominant aspect in these type of systems, and as a
consequence this holds too for their models.</p>
</div>
<div class="paragraph">
<p>The operating behavior of parallel processes can be described by different
formalisms, e.g. automata, Petri-nets or parallel processes. This text uses
the programming language Chi, which is an instance of a parallel processes
formalism.</p>
</div>
<div class="paragraph">
<p>A system is abstracted into a model, with cooperating processes, where
processes are connected to each other via channels.
The channels are used for exchanging material and information.
Models of the above mentioned examples consist of a number of concurrent
processes connected by channels, denoting the flow of products, patients or
personnel.</p>
</div>
<div class="paragraph">
<p>In Chi, communication takes place in a synchronous manner.
This means that communication between a sending process, and a receiving
process takes place only when both processes are able to communicate.
Processes and channels can dynamically be altered.
To model times, like inter-arrival times and server processing times, the
language has a notation of time.</p>
</div>
<div class="paragraph">
<p>The rationale behind the language is that models for the analysis of a system should be</p>
</div>
<div class="ulist">
<ul>
<li>
<p>formal (exactly one interpretation, every reader attaches the same meaning to the model),</p>
</li>
<li>
<p>easily writable (write the essence of the system in a compact way),</p>
</li>
<li>
<p>easily readable (non-experts should be able to understand the model),</p>
</li>
<li>
<p>and easily extensible (adding more details in one part should not affect other parts).</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Verification of the models to investigate the properties of the model should
be relatively effortless. (A model has to preserve some properties of the real system
otherwise results from the simulation study have no relation with the system
being modeled. The language must allow this verification to take place in a
simple manner.)</p>
</div>
<div class="paragraph">
<p>Experiments should be performed in an straightforward manner. (Minimizing the
effort in doing simulation studies, in particular for large systems, makes the
language useful.)</p>
</div>
<div class="paragraph">
<p>Finally, the used models should be usable for the supervisory (logic) control
of the systems (simulation studies often provide answers on how to control a
system in a better way, these answers should also work for the modeled
system).</p>
</div>
<div class="sect3">
<h4 id="tut-chi-in-a-nutshell">Chi in a nutshell</h4>
<div class="paragraph">
<p>During the past decades, the ancestors of Chi have been used with success,
for the analysis of a variety of (industrial) systems.
Based on this experience, the language Chi has been completely redesigned,
keeping the strong points of the previous versions, while making it more
powerful for advanced users, and easier to access for non-experts.</p>
</div>
<div class="paragraph">
<p>Its features are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A system (and its control) is modeled as a collection of parallel running
processes, communicating with each other using channels.</p>
</li>
<li>
<p>Processes do not share data with other processes and channels are
synchronous (sending and receiving is always done together at the same
time), making reasoning about process behavior easier.</p>
</li>
<li>
<p>Processes and channels are dynamic, new processes can be created as needed,
and communication channels can be created or rerouted.</p>
</li>
<li>
<p>Variables can have elementary values such as <em>boolean</em>, <em>integer</em> or <em>real</em>
numbers, to high level structured collections of data like <em>lists</em>, <em>sets</em>
and <em>dictionaries</em> to model the data of the system. If desired, processes
and channels can also be part of that data.</p>
</li>
<li>
<p>A small generic set of statements to describe algorithms, assignment, <em>if</em>,
<em>while</em>, and <em>for</em> statements. This set is relatively easy to explain to
non-experts, allowing them to understand the model, and participate in the
discussions.</p>
</li>
<li>
<p>Tutorials and manuals demonstrate use of the language for effective modeling
of system processes. More detailed modeling of the processes, or custom
tailoring them to the real situation, has no inherent limits.</p>
</li>
<li>
<p>Time and (quasi-) random number generation distributions are available for
modeling behavior of the system in time.</p>
</li>
<li>
<p>Likewise, measurements to derive performance indicators of the modeled
system are integrated in the model. Tutorials and manuals show basic use.
The integration allows for custom solutions to obtain the needed data in the
wanted form.</p>
</li>
<li>
<p>Input and output facilities from and to the file system exists to support
large simulation experiments.</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="tut-exercises">Exercises</h4>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Install the Chi programming environment at your computer.</p>
</li>
<li>
<p>Test your first program.</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>Construct the following program in a project in your workspace:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">model M():
writeln(&quot;It works!&quot;)
end</code></pre>
</div>
</div>
</li>
<li>
<p>Compile, and simulate the model as explained in the tool manual (in
<a href="#tool-compile-and-simulate">Compile and simulate</a>).</p>
</li>
<li>
<p>Try to explain the result.</p>
</li>
</ol>
</div>
</li>
<li>
<p>Test a program with model parameters.</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>Construct the following program in the same manner:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">model M(string s):
write(&quot;%s\n&quot;)
end</code></pre>
</div>
</div>
</li>
<li>
<p>Simulate the model, where you have to set the <em>Model instance</em> text to
<code>M("OOPS")</code> in the dialog box of the simulator.</p>
</li>
<li>
<p>Try to explain the result.</p>
</li>
</ol>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p></p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="tut-chapter-data-types">Data types</h3>
<div class="paragraph">
<p>The language is a statically typed language, which means that all variables
and values in a model have a single fixed type.
All variables must be declared in the program.
The declaration of a variable consists of the type, and the name, of the
variable. The following fragment shows the declaration of two elementary data
types, integer variable <code>i</code> and real variable <code>r</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">...
int i;
real r;
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>The ellipsis (<code>...</code>) denotes that non-relevant information is left out from
the fragment. The syntax for the declaration of variables is similar to the
language <em>C</em>. All declared variables are initialized, variables <code>i</code> and
<code>r</code> are both initialized to zero.</p>
</div>
<div class="paragraph">
<p>An expression, consisting of operators, e.g. plus (<code>+</code>), times (<code>*</code>), and
operands, e.g. <code>i</code> and <code>r</code>, is used to calculate a new value. The new
value can be assigned to a variable by using an <em>assignment</em> statement. An
example with four variables, two expressions and assignment statements is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">...
int i = 2, j;
real r = 1.50, s;
j = 2 * i + 1;
s = r / 2;
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>The value of variable <code>j</code> becomes <code>5</code>, and the value of <code>s</code> becomes
<code>0.75</code>.
Statements are described in <a href="#tut-chapter-statements">Statements</a>.</p>
</div>
<div class="paragraph">
<p>Data types are categorized in five different groups: <em>elementary</em> types,
<em>tuple</em> types, <em>container</em> types, <em>custom</em> types, and <em>distribution</em> types.
Elementary types are types such as Boolean, integer, real or string.
Tuple types contain at least one element, where each element can be of
different type. In other languages tuple types are called records (Pascal) or
structures (C).
Variables with a container type (a list, set, or dictionary) contain many
elements, where each element is of the same type.
Custom types are created by the user to enhance the readability of the model.
Distributions types are types used for the generation of distributions from
(pseudo-) random numbers.
They are covered in <a href="#tut-chapter-stochastic-behavior">Modeling stochastic behavior</a>.</p>
</div>
<div class="sect3">
<h4 id="tut-elementary-types">Elementary types</h4>
<div class="paragraph">
<p>The elementary data types are Booleans, numbers and strings.
The language provides the elementary data types:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>bool</code> for booleans, with values <code>false</code> and <code>true</code>.</p>
</li>
<li>
<p><code>enum</code> for enumeration types, for example
<code>enum FlagColors = {red, white, blue}</code>,</p>
</li>
<li>
<p><code>int</code> for integers, e.g. <code>-7</code>, <code>20</code>, <code>0</code>.</p>
</li>
<li>
<p><code>real</code> for reals, e.g. <code>3.14</code>, <code>7.0e9</code>.</p>
</li>
<li>
<p><code>string</code> for text strings, e.g. <code>"Hello"</code>, <code>"world"</code>.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>
</p>
</div>
<div class="sect4">
<h5 id="tut-booleans">Booleans</h5>
<div class="paragraph">
<p>A boolean value has two possible values, the truth values.
These truth values are <code>false</code> and <code>true</code>.
The value <code>false</code> means that a property is not fulfilled.
A value <code>true</code> means the presence of a property.
Boolean variables are initialized with the value <code>false</code>.</p>
</div>
<div class="paragraph">
<p>In mathematics, various symbols are used for unary and binary boolean
operators.
These operators are also present in Chi.
The most commonly used boolean operators are <code>not</code>, <code>and</code>, and <code>or</code>.
The names of the operators, the symbols in mathematics and the symbols in the
language are presented in <a href="#tut-table-boolsymbols">Table with boolean symbols</a>.</p>
</div>
<table id="tut-table-boolsymbols" class="tableblock frame-all grid-all stretch">
<caption class="title">Table 1. Table with boolean symbols</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Operator</th>
<th class="tableblock halign-left valign-top">Math</th>
<th class="tableblock halign-left valign-top">Chi</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean not</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">¬</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>not</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean and</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>and</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean or</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>or</code></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>Examples of boolean expressions are the following.
If <code>z</code> equals <code>true</code>, then the value of <code>(not z)</code> equals <code>false</code>.
If <code>s</code> equals <code>false</code>, and <code>t</code> equals <code>true</code>, then the value of the
expression <code>(s or t)</code> becomes <code>true</code>.</p>
</div>
<div class="paragraph">
<p>
The result of the unary <code>not</code>, the binary
<code>and</code> and <code>or</code> operators, for two variables <code>p</code> and <code>q</code> is given in
<a href="#tut-table-truthtable">Truth table for <code>not</code>, <code>and</code> and <code>or</code> operators</a>.</p>
</div>
<table id="tut-table-truthtable" class="tableblock frame-all grid-all stretch">
<caption class="title">Table 2. Truth table for <code>not</code>, <code>and</code> and <code>or</code> operators</caption>
<colgroup>
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top"><code>p</code></th>
<th class="tableblock halign-left valign-top"><code>q</code></th>
<th class="tableblock halign-left valign-top"><code>not p</code></th>
<th class="tableblock halign-left valign-top"><code>p and q</code></th>
<th class="tableblock halign-left valign-top"><code>p or q</code></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>false</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>If <code>p = true</code> and <code>q = false</code>, we find for <code>p or q</code> the value <code>true</code>
(third line in <a href="#tut-table-truthtable">Truth table for <code>not</code>, <code>and</code> and <code>or</code> operators</a>).</p>
</div>
<div class="paragraph">
<p>
</p>
</div>
</div>
<div class="sect4">
<h5 id="tut-enumerations">Enumerations</h5>
<div class="paragraph">
<p>Often there are several variants of entities, like types of products,
available resources, available machine types, and so on.</p>
</div>
<div class="paragraph">
<p>One way of coding them is give each a unique number, which results in code
with a lot of small numbers that are not actually numbers, but refer to one
variant.</p>
</div>
<div class="paragraph">
<p>Another way is to give each variant a name (which often already exists), and
use those names instead.</p>
</div>
<div class="paragraph">
<p>For example, to model a traffic light:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">enum TrafficColor = {RED, ORANGE, GREEN};
TrafficColor light = RED;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>enum TrafficColor</code> line lists the available traffic colors. With this
definition, a new type <code>TrafficColor</code> is created, which you can use like any
other type. The line <code>TrafficColor light = RED;</code> creates a new variable
called <code>light</code> and initializes it to the value <code>RED</code>.</p>
</div>
<div class="paragraph">
<p>
</p>
</div>
</div>
<div class="sect4">
<h5 id="tut-numbers">Numbers</h5>
<div class="paragraph">
<p>In the language, two types of numbers are available: integer numbers and real
numbers. Integer numbers are whole numbers, denoted by type <code>int</code> e.g.
<code>3</code>, <code>-10</code>, <code>0</code>. Real numbers are used to present numbers with a
fraction, denoted by type <code>real</code>. E.g. <code>3.14</code>, <code>2.7e6</code> (the scientific
notation for 2.7 million). Note that real numbers <em>must</em> either have a
fraction or use the scientific notation, to let the computer know you mean a
real number (instead of an integer number). Integer variables are initialized
with <code>0</code>. Real variables are initialized with <code>0.0</code>.</p>
</div>
<div class="paragraph">
<p>
For numbers, the normal arithmetic operators are defined.
Expressions can be constructed with these operators.
The arithmetic operators for numbers are listed in <a href="#tut-table-aritoper">The arithmetic operators</a>.</p>
</div>
<table id="tut-table-aritoper" class="tableblock frame-all grid-all stretch">
<caption class="title">Table 3. The arithmetic operators</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Operator name</th>
<th class="tableblock halign-left valign-top">Notation</th>
<th class="tableblock halign-left valign-top">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">unary plus</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>+ x</code></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">unary minus</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>- x</code></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">raising to the power</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x ^ y</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Always a <code>real</code> result.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">multiplication</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x * y</code></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">real division</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x / y</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Always a <code>real</code> result.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">division</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x div y</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">For <code>int</code> only.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">modulo</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x mod y</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">For <code>int</code> only.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">addition</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x + y</code></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">subtraction</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x - y</code></p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>The priority of the operators is given from high to low.
The unary operators have the strongest binding, and the <code>+</code> and <code>-</code> the
weakest binding. So, <code>-3^2</code> is read as <code>(-3)^2</code> and not <code>-(3^2)</code>,
because the priority rules say that the unary operator binds stronger than the
raising to the power operator. Binding in expressions can be changed by the
use of parentheses.</p>
</div>
<div class="paragraph">
<p>The integer division, denoted by <code>div</code>, gives the biggest integral number
smaller or equal to <code>x / y</code>. The integer remainder, denoted by <code>mod</code>,
gives the remainder after division <code>x - y * (x div y)</code>. So, <code>7 div 3</code>
gives <code>2</code> and <code>-7 div 3</code> gives <code>-3</code>, <code>7 mod 3</code> gives <code>1</code> and <code>-7
mod 3</code> gives <code>2</code>.</p>
</div>
<div class="paragraph">
<p>The rule for the result of an operation is as follows. The real division and
raising to the power operations always produce a value of type <code>real</code>.
Otherwise, if both operands (thus <code>x</code> and <code>y</code>) are of type <code>int</code>, the
result of the operation is of type <code>int</code>. If one of the operands is of type
<code>real</code>, the result of the operation is of type <code>real</code>.</p>
</div>
<div class="paragraph">
<p>
Conversion functions exist to convert a real into an integer.
The function <code>ceil</code> converts a real to the
smallest integer value not less than the real, the
function <code>floor</code> gives the biggest
integer value smaller than or equal to the real, and the
function <code>round</code> rounds the real to the nearest integer
value (or up, if it ends on <code>.5</code>).</p>
</div>
<div class="paragraph">
<p>
Between two numbers a relational operation can be defined.
If for example variable <code>x</code> is smaller than variable <code>y</code>, the expression
<code>x &lt; y</code> equals <code>true</code>. The relational operators, with well-known
semantics, are listed in <a href="#tut-table-reloper">The relational operators</a>.</p>
</div>
<table id="tut-table-reloper" class="tableblock frame-all grid-all stretch">
<caption class="title">Table 4. The relational operators</caption>
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Operator</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">less than</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x &lt; y</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">at most</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x &lt;= y</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">equals</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x == y</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">differs from</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x != y</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">at least</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x &gt;= y</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">greater than</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>x &gt; y</code></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>
</p>
</div>
</div>
<div class="sect4">
<h5 id="tut-strings">Strings</h5>
<div class="paragraph">
<p>Variables of type string contains a sequence of characters.
A string is enclosed by double quotes.
An example is <code>"Manufacturing line"</code>.
Strings can be composed from different strings.
The concatenation operator (<code>+</code>) adds one string to another, for
example <code>"One" + " " + "string"</code> gives <code>"One string"</code>.
Moreover the relational operators (<code>&lt;</code>, <code>&lt;=</code>, <code>==</code>, <code>!=</code> <code>&gt;=</code>,
and <code>&gt;</code>) can be used to compare strings alphabetically,
e.g. <code>"a" &lt; "aa" &lt; "ab" &lt; "b"</code>.
String variables are initialized with the empty string <code>""</code>.</p>
</div>
<div class="paragraph">
<p>
</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="tut-tuple-types">Tuple types</h4>
<div class="paragraph">
<p>
Tuple types are used for keeping several (related) kinds of data together in
one variable, e.g. the name and the age of a person.
A tuple variable consists of a number of fields
inside the tuple, where the types of these fields may be different.
The number of fields is fixed. One operator, the projection operator
denoted by a dot (<code>.</code>), is defined for tuples. It selects a field in the
tuple for reading or assigning.</p>
</div>
<div class="sect4">
<h5 id="tut-notation">Notation</h5>
<div class="paragraph">
<p>A type <code>person</code> is a tuple with two fields, a 'name' field of type
<code>string</code>, and an 'age' field of type <code>int</code>, is denoted by:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">type person = tuple(string name; int age)</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="tut-operator">Operator</h5>
<div class="paragraph">
<p>A projection operator fetches a field from a tuple.
We define two persons:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">person eva = (&quot;eva&quot; , 29),
adam = (&quot;adam&quot;, 27);</code></pre>
</div>
</div>
<div class="paragraph">
<p>And we can speak of <code>eva.name</code> and <code>adam.age</code>, denoting the name of
<code>eva</code> (<code>"eva"</code>) and the age of <code>adam</code> (<code>27</code>).
We can assign a field in a tuple to another variable:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">ae = eva.age;
eva.age = eva.age + 1;</code></pre>
</div>
</div>
<div class="paragraph">
<p>This means that the age of <code>eva</code> is assigned tot variable <code>ae</code>, and the
new age of <code>eva</code> becomes <code>eva.age + 1</code>.</p>
</div>
<div class="paragraph">
<p>By using a multi assignment statement all values of a tuple can be copied into
separate variables:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">string name;
int age;
name, age = eva</code></pre>
</div>
</div>
<div class="paragraph">
<p>This assignment copies the name of <code>eva</code> into variable <code>name</code> of type
<code>string</code> and her age into <code>age</code> of type <code>int</code>.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="tut-container-types">Container types</h4>
<div class="paragraph">
<p>Lists, sets and dictionaries are container types.
A variable of this type contains zero or more identical elements.
Elements can be added or removed in variables of these types.
Variables of a container type are initialized with zero elements.</p>
</div>
<div class="paragraph">
<p>Sets are unordered collections of elements. Each element value either exists
in a set, or it does not exist in a set.
Each element value is unique, duplicate elements are silently discarded.
A list is an ordered collection of elements, that is, there is a first and a last
element (in a non-empty list). A list also allows duplicate element values.
Dictionaries are unordered and have no duplicate value, just like sets, but
you can associate a value (of a different type) with each element value.</p>
</div>
<div class="paragraph">
<p>
Lists are denoted by a pair of (square) brackets.
For example, <code>[7, 8, 3]</code> is a list with three integer elements. Since a list
is ordered, <code>[8, 7, 3]</code> is a different list.
With empty lists, the computer has to know the type of the elements, e.g.
<code>&lt;int&gt;[]</code> is an empty list with integer elements.
The prefix <code>&lt;int&gt;</code> is required in this case.</p>
</div>
<div class="paragraph">
<p>
Sets are denoted by a
pair of (curly) braces, e.g. <code>{7, 8, 3}</code> is a set with three integer
elements.
As with lists, for an empty set a prefix is required, for example
<code>&lt;string&gt;{}</code> is an empty set with strings.
A set is an unordered collection of elements.
The set <code>{7, 8, 3}</code> is a set with three integer numbers. Since order of
the elements does not matter, the same set can also be written as
<code>{8, 3, 7}</code> (or in one of the four other orders).
In addition, each element in a set is unique, the set <code>{8, 7, 8, 3}</code> is
equal to the set <code>{7, 8, 3}</code>.
For readability, elements in a set are normally written in increasing order,
for example <code>{3, 7, 8}</code>.</p>
</div>
<div class="paragraph">
<p>
Dictionaries are denoted by a pair of (curly) braces, whereby an element value
consists of two parts, a 'key' and a 'value' part.
The two parts separated by a colon (<code>:</code>).
For example <code>{"jim" : 32, "john" : 34}</code> is a dictionary with two elements.
The first element has <code>"jim"</code> as key part and <code>32</code> as value part, the
second element has <code>"john"</code> as key part and <code>34</code> as value part.
The key parts of the elements work like a set, they are unordered and
duplicates are silently discarded. A value part is associated with its key
part.
In this example, the key part is the name of a person, while the value part
keeps the age of that person.
Empty dictionaries are written with a type prefix just like lists and sets,
e.g. <code>&lt;string:int&gt;{}</code>.</p>
</div>
<div class="paragraph">
<p>Container types have some built-in functions in common (Functions are
described in <a href="#tut-chapter-functions">Functions</a>):</p>
</div>
<div class="paragraph">
<p>
</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The function <code>size</code> gives the number of elements in a variable, for
example <code>size([7, 8, 3])</code> yields 3; <code>size({7, 8})</code> results in 2;
<code>size({"jim":32})</code> gives 1 (an element consists of two parts).</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>
</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The function <code>empty</code> yields <code>true</code> if there are no elements in variable.
E.g. <code>empty(&lt;string&gt;{})</code> with an empty set of type <code>string</code> is true.
(Here the type <code>string</code> is needed to determine the type of the elements
of the empty set.)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>
</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The function <code>pop</code> extracts a value from the provided collection and
returns a tuple with that value, and the collection minus the value.</p>
<div class="paragraph">
<p>
For lists, the first element of the list
becomes the first field of the tuple. The second field of the tuple becomes
the list minus the first list element. For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">pop([7, 8, 3]) -&gt; (7, [8, 3])</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>-&gt;</code> above denotes 'yields'.
The value of the list is split into a 'head' (the first element) and a
'tail' (the remaining elements).</p>
</div>
<div class="paragraph">
<p>
For sets, the first field of the tuple becomes the
value of an arbitrary element from the set. The second field of the tuple
becomes the original set minus the arbitrary element.
For example, a <code>pop</code> on the set <code>{8, 7, 3}</code> has three possible answers:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">pop({8, 7, 3}) -&gt; (7, {3, 8}) or
pop({8, 7, 3}) -&gt; (3, {7, 8}) or
pop({8, 7, 3}) -&gt; (8, {3, 7})</code></pre>
</div>
</div>
<div class="paragraph">
<p>
Performing a <code>pop</code> on a dictionary
follows the same pattern as above, except 'a value from the collection' are
actually a key item and a value item. In this case, the <code>pop</code> function
gives a three-tuple as result. The first field of the tuple becomes the key
of the extracted element, the second field of the tuple becomes the value of
the element, and the third field of the tuple contains the dictionary except
for the extracted element. Examples:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">pop({&quot;a&quot; : 32, &quot;b&quot; : 34}) -&gt; (&quot;a&quot;, 32, {&quot;b&quot; : 34}) or
pop({&quot;a&quot; : 32, &quot;b&quot; : 34}) -&gt; (&quot;b&quot;, 34, {&quot;a&quot; : 32})</code></pre>
</div>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>
</p>
</div>
<div class="sect4">
<h5 id="tut-lists">Lists</h5>
<div class="paragraph">
<p>A list is an ordered collection of elements of the same type.
They are useful to model anything where duplicate values may occur or where
order of the values is significant. Examples are waiting customers in a shop,
process steps in a recipe, or products stored in a warehouse. Various
operations are defined for lists.</p>
</div>
<div class="paragraph">
<p>An element can be fetched by <em>indexing</em>.
This indexing operation does not change the content of the variable.
The first element of a list has index <code>0</code>.
The last element of a list has index <code>size(xs) - 1</code>.
A negative index, say <code>m</code>, starts from the back of the list, or
equivalently, at offset <code>size(xs) + m</code> from the front.
You cannot index non-existing elements.
Some examples, with <code>xs = [7, 8, 3, 5, 9]</code> are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">xs[0] -&gt; 7
xs[3] -&gt; 5
xs[5] -&gt; ERROR (there is no element at position 5)
xs[-1] -&gt; xs[5 - 1] -&gt; xs[4] -&gt; 9
xs[-2] -&gt; xs[5 - 2] -&gt; xs[3] -&gt; 5</code></pre>
</div>
</div>
<div class="paragraph">
<p>
In <a href="#tut-figure-list-with-indices">A list with indices</a> the list with indices is visualized.
A common name for the first element of a list
(i.e., <code>x[0]</code>) is the <em>head</em> of a list.
Similarly, the last element of a list
(<code>xs[-1]</code>) is also known as <em>head right</em>.</p>
</div>
<div id="tut-figure-list-with-indices" class="imageblock">
<div class="content">
<img src="./tutorial/pictures/list_with_indices.png" alt="list with indices">
</div>
<div class="title">Figure 1. A list with indices</div>
</div>
<div class="paragraph">
<p>A part of a list can be fetched by <em>slicing</em>.
The slicing operation does not change the content of the list, it copies a
contiguous sequence of a list.
The result of a slice operation is again a list, even if the slice contains
just one element.</p>
</div>
<div class="paragraph">
<p>Slicing is denoted by <code>xs[i:j]</code>.
The slice of <code>xs[i:j]</code> is defined as the sequence of elements with index
<code>k</code> such that <code>i &lt;= k &lt; j</code>. Note the upper bound <code>j</code> is noninclusive.
If <code>i</code> is omitted use <code>0</code>.
If <code>j</code> is omitted use <code>size(xs)</code>. If <code>i</code> is greater than or equal to
<code>j</code>, the slice is empty. If <code>i</code> or <code>j</code> is negative, the index is
relative to the end of the list: <code>size(xs) + i</code> or <code>size(xs) + j</code> is
substituted. Some examples with <code>xs = [7, 8, 3, 5, 9]</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">xs[1:3] -&gt; [8, 3]
xs[:2] -&gt; [7, 8]
xs[1:] -&gt; [8, 3, 5, 9]
xs[:-1] -&gt; [7, 8, 3, 5]
xs[:-3] -&gt; [7, 8]</code></pre>
</div>
</div>
<div class="paragraph">
<p>
The list of all but the first elements (<code>xs[1:]</code>) is often called <em>tail</em>
and <code>xs[:-1]</code> is also known as <em>tail right</em>.
In <a href="#tut-figure-list-with-slices">A list with indices and slices</a> the slicing operator is visualized.</p>
</div>
<div id="tut-figure-list-with-slices" class="imageblock">
<div class="content">
<img src="./tutorial/pictures/list_with_slices.png" alt="list with slices">
</div>
<div class="title">Figure 2. A list with indices and slices</div>
</div>
<div class="paragraph">
<p>
Two lists can be 'glued' together into a new list.
The glue-ing or concatenation of a list with elements <code>7</code>, <code>8</code>, <code>3</code> and a
list with elements <code>5</code>, and <code>9</code> is denoted by:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">[7, 8, 3] + [5, 9] -&gt; [7, 8, 3, 5, 9]</code></pre>
</div>
</div>
<div class="paragraph">
<p>An element can be added to a list at the rear or at the front.
The action is performed by transforming the element into a list and then
concatenate these two lists. In the next example the value <code>5</code> is added to
the rear, respectively the front, of a list:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">[7, 8, 3] + [5] -&gt; [7, 8, 3, 5]
[5] + [7, 8, 3] -&gt; [5, 7, 8, 3]</code></pre>
</div>
</div>
<div class="paragraph">
<p>
Elements also can be removed from a list.
The <code>del</code> function removes by position, e.g. <code>del(xs, 2)</code> returns the list
<code>xs</code> without its third element (since positions start at index 0).
Removing a value by value can be performed by the subtraction operator <code>-</code>.
For instance, consider the following subtractions:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">[1, 4, 2, 4, 5] - [2] -&gt; [1, 4, 4, 5]
[1, 4, 2, 4, 5] - [4] -&gt; [1, 2, 4, 5]
[1, 4, 2, 4, 5] - [8] -&gt; [1, 4, 2, 4, 5]</code></pre>
</div>
</div>
<div class="paragraph">
<p>Every element in the list at the right is searched in the list at the left,
and if found, the <em>first</em> occurrence is removed.
In the first example, element <code>2</code> is removed. In the second example, only
the first value <code>4</code> is removed and the second value (at position 3) is kept.
In the third example, nothing is removed, since value <code>8</code> is not in the list
at the left.</p>
</div>
<div class="paragraph">
<p>When the list at the right is longer than one element, the operation is repeated.
For example, consider <code>xs - ys</code>, whereby <code>xs = [1, 2, 3, 4, 5]</code> and
<code>ys = [6, 4, 2, 3]</code>. The result is computed as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi"> [1, 2, 3, 4, 5] - [6, 4, 2, 3]
-&gt; ([1, 2, 3, 4, 5] - [6]) - [4, 2, 3]
-&gt; [1, 2, 3, 4, 5] - [4, 2, 3]
-&gt; ([1, 2, 3, 4, 5] - [4]) - [2, 3]
-&gt; [1, 2, 3, 5] - [2, 3]
-&gt; ([1, 2, 3, 5] - [2]) - [3]
-&gt; [1, 3, 5] - [3]
-&gt; [1,5]</code></pre>
</div>
</div>
<div class="paragraph">
<p>Lists have two relational operators, the equal operator and the not-equal operator.
The equal operator (<code>==</code>) compares two lists. If the lists have the same
number of elements and all the elements are pair-wise the same, the result of
the operation is <code>true</code>, otherwise <code>false</code>.
The not-equal operator (<code>!=</code>) does the same check, but with an opposite result.
Some examples, with <code>xs = [7, 8, 3]</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">xs == [7, 8, 3] -&gt; true
xs == [7, 7, 7] -&gt; false</code></pre>
</div>
</div>
<div class="paragraph">
<p>The membership operator (<code>in</code>) checks if an element is in a list.
Some examples, with <code>xs = [7, 8, 3]</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">6 in xs -&gt; false
7 in xs -&gt; true
8 in xs -&gt; true</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="tut-initialization">Initialization</h5>
<div class="paragraph">
<p>A list variable is initialized with a list with zero elements, for example in:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">list int xs;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The initial value of <code>xs</code> equals <code>&lt;int&gt;[]</code>.</p>
</div>
<div class="paragraph">
<p>A list can be initialized with a number, denoting the number of elements in the list:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">list(2) int ys</code></pre>
</div>
</div>
<div class="paragraph">
<p>This declaration creates a list with <code>2</code> elements, whereby each element of
type <code>int</code> is initialized.
The initial value of <code>ys</code> equals <code>[0, 0]</code>.
Another example with a list of lists:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">list(4) list(2) int zm</code></pre>
</div>
</div>
<div class="paragraph">
<p>This declaration initializes variable <code>zm</code> with the value
<code>[ [0, 0], [0, 0], [0, 0], [0, 0] ]</code>.</p>
</div>
<div class="paragraph">
<p>
</p>
</div>
</div>
<div class="sect4">
<h5 id="tut-sets">Sets</h5>
<div class="paragraph">
<p>Set operators for union, intersection and difference are present.
<a href="#tut-table-set-operations">Table with set operations</a> gives the name, the mathematical notation and
the notation in the Chi language.</p>
</div>
<table id="tut-table-set-operations" class="tableblock frame-all grid-all stretch">
<caption class="title">Table 5. Table with set operations</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Operator</th>
<th class="tableblock halign-left valign-top">Math</th>
<th class="tableblock halign-left valign-top">Chi</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">set union</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>+</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">set intersection</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>*</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">set difference</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>-</code></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>The union of two sets merges the values of both sets into one, that is, the
result is the collection of values that appear in at least one of the
arguments of the union operation. Some examples:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">{3, 7, 8} + {5, 9} -&gt; {3, 5, 7, 8, 9}</code></pre>
</div>
</div>
<div class="paragraph">
<p>All permutations with the elements <code>3</code>, <code>5</code>, <code>7</code>, <code>8</code> and <code>9</code> are
correct (sets have no order, all permutations are equivalent). To keep sets
readable the elements are sorted in increasing order in this tutorial.</p>
</div>
<div class="paragraph">
<p>Values that occur in both arguments, appear only one time in the result (sets
silently discard duplicate elements). For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">{3, 7, 8} + {7, 9} -&gt; {3, 7, 8, 9}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The intersection of two sets gives a set with the common elements, that is,
all values that occur in <em>both</em> arguments.
Some examples:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">{3, 7, 8} * {5, 9} -&gt; &lt;int&gt;{} # no common element
{3, 7, 8} * {7, 9} -&gt; {7} # only 7 in common</code></pre>
</div>
</div>
<div class="paragraph">
<p>Set difference works much like subtraction on lists, except elements occur at
most one time (and have no order). The operation computes 'remaining
elements'. The result is a new set containing all values from the first set
which are not in the second set.
Some examples:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">{3, 7, 8} - {5, 9} -&gt; {3, 7, 8}
{3, 7, 8} - {7, 9} -&gt; {3, 9}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The membership operator <code>in</code> works on sets too:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">3 in {3, 7, 8} -&gt; true
9 in {3, 7, 8} -&gt; false</code></pre>
</div>
</div>
<div class="paragraph">
<p>
</p>
</div>
</div>
<div class="sect4">
<h5 id="tut-dictionaries">Dictionaries</h5>
<div class="paragraph">
<p>Elements of dictionaries are stored according to a key, while lists elements
are ordered by a (relative) position, and set elements are not ordered at all.
A dictionary can grow and shrink by adding or removing elements respectively,
like a list or a set.
An element of a dictionary is accessed by the key of the element.</p>
</div>
<div class="paragraph">
<p>The dictionary variable <code>d</code> of type <code>dict(string : int)</code> is given by:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">dict (string : int) d =
{&quot;jim&quot; : 32,
&quot;john&quot; : 34,
&quot;adam&quot; : 25}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Retrieving values of the dictionary by using the key:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">d[&quot;john&quot;] -&gt; 34
d[&quot;adam&quot;] -&gt; 25</code></pre>
</div>
</div>
<div class="paragraph">
<p>Using a non-existing key to retrieve a value results in a error message.</p>
</div>
<div class="paragraph">
<p>A new value can be assigned to the variable by selecting the key of the element:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">d[&quot;john&quot;] = 35</code></pre>
</div>
</div>
<div class="paragraph">
<p>This assignment changes the value of the <code>"john"</code> item to <code>35</code>.
The assignment can also be used to add new items:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">d[&quot;lisa&quot;] = 19</code></pre>
</div>
</div>
<div class="paragraph">
<p>Membership testing of keys in dictionaries can be done with the <code>in</code> operator:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">&quot;jim&quot; in d -&gt; true
&quot;peter&quot; in d -&gt; false</code></pre>
</div>
</div>
<div class="paragraph">
<p>Merging two dictionaries is done by adding them together. The value of the
second dictionary is used when a key exists in both dictionaries:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">{1 : 1, 2 : 2} + {1 : 5, 3 : 3} -&gt; {1 : 5, 2 : 2, 3 : 3}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The left dictionary is copied, and updated with each item of the right dictionary.</p>
</div>
<div class="paragraph">
<p>Removing elements can be done with subtraction, based on key values. Lists and
sets can also be used to denote which keys should be removed.
A few examples for <code>p</code> is <code>{1 : 1, 2 : 2}</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">p - {1 : 3, 5 : 5} -&gt; {2 : 2}
p - {1, 7} -&gt; {2 : 2}
p - [2, 8] -&gt; {1 : 1}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Subtracting keys that do not exist in the left dictionary is allowed and has
no effect.</p>
</div>
<div class="paragraph">
<p></p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="tut-custom-types">Custom types</h4>
<div class="paragraph">
<p>To structure data the language allows the creation of new types. The
definition can only be done at global level, that is, outside any <code>proc</code>,
<code>func</code>, <code>model</code>, or <code>xper</code> definition.</p>
</div>
<div class="paragraph">
<p>Types can be used as alias for elementary data types to increase readability,
for example a variable of type <code>item</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">type item = real;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Variables of type <code>item</code> are, e.g.:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">item box, product;
box = 4.0; product = 120.5;</code></pre>
</div>
</div>
<div class="paragraph">
<p>This definition creates the possibility to speak about an item.</p>
</div>
<div class="paragraph">
<p>Types also can be used to make combinations of other data types, e.g. a
recipe:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">type step = tuple(string name; real process_time),
recipe = tuple(int id; list step steps);</code></pre>
</div>
</div>
<div class="paragraph">
<p>A type <code>step</code> is defined by a <code>tuple</code> with two fields, a field with
<code>name</code> of type <code>string</code>, denoting the name of the step, and a field with
<code>process_time</code> of type <code>real</code>, denoting the duration of the (processing)
step.
The <code>step</code> definition is used in the type <code>recipe</code>.
Type <code>recipe</code> is defined by a <code>tuple</code> with two fields, an <code>id</code> of type
<code>int</code>, denoting the identification number, and a field <code>steps</code> of type
<code>list step</code>, denoting a list of single steps.
Variables of type recipe are, e.g.:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">recipe plate, bread;
plate = (34, [(&quot;s&quot;, 10.8), (&quot;w&quot;, 13.7), (&quot;s&quot;, 25.6)]);
bread = (90, [(&quot;flour&quot;, 16.3), (&quot;yeast&quot;, 6.9)]);</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="tut-exercises-2">Exercises</h4>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Exercises for integer numbers.
What is the result of the following expressions:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">-5 ^ 3
-5 * 3
5 mod 3</code></pre>
</div>
</div>
</li>
<li>
<p>Exercises for tuples.
Given are tuple type <code>box</code> and variable <code>x</code> of type <code>box</code>:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">type box = tuple(string name; real weight);
box x = (&quot;White&quot;, 12.5);</code></pre>
</div>
</div>
<div class="paragraph">
<p>What is the result of the following expressions:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">x.name
x.real
x</code></pre>
</div>
</div>
</li>
<li>
<p>Exercises for lists.
Given is the list <code>xs = [0,1,2,3,4,5,6]</code>.
Determine the outcome of:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">xs[0]
xs[1:]
size(xs)
xs + [3]
[4,5] + xs
xs - [2,2,3]
xs - xs[2:]
xs[0] + (xs[1:])[0]</code></pre>
</div>
</div>
</li>
</ol>
</div>
</div>
</div>
<div class="sect2">
<h3 id="tut-chapter-statements">Statements</h3>
<div class="paragraph">
<p>There are several kinds of statements, such as assignment statements, choice
statements (select and if statements), and loop statements (while and for
statements).</p>
</div>
<div class="paragraph">
<p>Semicolons are required after statements, except at the end of a sequence
(that is, just before an <code>end</code> keyword and after the last statement) or
after the keyword <code>end</code>. In this text semicolons are omitted before <code>end</code>.</p>
</div>
<div class="paragraph">
<p>
</p>
</div>
<div class="sect3">
<h4 id="tut-the-assignment-statement">The assignment statement</h4>
<div class="paragraph">
<p>An <em>assignment</em> statement is used to assign values to variables.
An example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">y = x + 10</code></pre>
</div>
</div>
<div class="paragraph">
<p>This assignment consists of a name of the variable (<code>y</code>), an assignment
symbol (<code>=</code>), and an expression (<code>x + 10</code>) yielding a value. For example,
when <code>x</code> is <code>2</code>, the value of the expression is <code>12</code>.
Execution of this statement copies the value to the <code>y</code> variable,
immediately after executing the assignment, the value of the <code>y</code> variable is
<code>10</code> larger than the value of the <code>x</code> variable at this point of the
program.
The value of the <code>y</code> variable will not change until the next assignment to
<code>y</code>, for example, performing the assignment <code>x = 7</code> has no effect on the
value of the <code>y</code> variable.</p>
</div>
<div class="paragraph">
<p>An example with two assignment statements:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">i = 2;
j = j + 1</code></pre>
</div>
</div>
<div class="paragraph">
<p>The values of <code>i</code> becomes 2, and the value of <code>j</code> is incremented.
Independent assignments can also be combined in a multi-assignment, for
example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">i, j = 2, j + 1</code></pre>
</div>
</div>
<div class="paragraph">
<p>The result is the same as the above described example, the first value goes
into the first variable, the second value into the second variable, etc.</p>
</div>
<div class="paragraph">
<p>In an assignment statement, first all expression values are computed before
any assignment is actually done. In the following example the values of <code>x</code>
and <code>y</code> are swapped:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">x, y = y, x;</code></pre>
</div>
</div>
<div class="paragraph">
<p>
</p>
</div>
</div>
<div class="sect3">
<h4 id="tut-the-if-statement">The <code>if</code> statement</h4>
<div class="paragraph">
<p>The <em>if</em> statement is used to express decisions.
An example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">if x &lt; 0:
y = -x
end</code></pre>
</div>
</div>
<div class="paragraph">
<p>If the value of <code>x</code> is negative, assign its negated value to <code>y</code>.
Otherwise, do nothing (skip the <code>y = -x</code> assignment statement).</p>
</div>
<div class="paragraph">
<p>To perform a different statement when the decision fails, an <code>if</code>-statement
with an <code>else</code> alternative can be used. It has the following form.
An example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">if a &gt; 0:
c = a
else:
c = b
end</code></pre>
</div>
</div>
<div class="paragraph">
<p>If <code>a</code> is positive, variable <code>c</code> gets the value of <code>a</code>, otherwise it
gets the value of <code>b</code>.</p>
</div>
<div class="paragraph">
<p>In some cases more alternatives must be tested. One way of writing it is by
nesting an <code>if</code>-statement in the <code>else</code> alternative of the previous
<code>if</code>-statement, like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">if i &lt; 0:
writeln(&quot;i &lt; 0&quot;)
else:
if i == 0:
writeln(&quot;i = 0&quot;)
else:
if i &gt; 0 and i &lt; 10:
writeln(&quot;0 &lt; i &lt; 10&quot;)
else:
# i must be greater or equal 10
writeln(&quot;i &gt;= 10&quot;)
end
end
end</code></pre>
</div>
</div>
<div class="paragraph">
<p>This tests <code>i &lt; 0</code>. If it fails, the <code>else</code> is chosen, which contains a
second <code>if</code>-statement with the <code>i == 0</code> test. If that test also fails, the
third condition <code>i &gt; 0 and i &lt; 10</code> is tested, and one of the <code>writeln</code>
statements is chosen.</p>
</div>
<div class="paragraph">
<p>The above can be written more compactly by combining an <code>else</code>-part and the
<code>if</code>-statement that follows, into an <code>elif</code> part. Each <code>elif</code> part
consists of a boolean expression, and a statement list. Using <code>elif</code> parts
results in:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="chi">if i &lt; 0:
writeln(&quot;i &lt; 0&quot;)
elif i == 0:
writeln(&quot;i = 0&quot;)
elif i &gt; 0 and i &lt; 10: