[Swift-commit] r4921 - trunk/docs/tutorial

wilde at ci.uchicago.edu wilde at ci.uchicago.edu
Mon Aug 1 14:04:52 CDT 2011


Author: wilde
Date: 2011-08-01 14:04:52 -0500 (Mon, 01 Aug 2011)
New Revision: 4921

Removed:
   trunk/docs/tutorial/tutorial.html
Log:
Removed tutorial.html - thats supposed to be a generated file, should not be in svn.

Deleted: trunk/docs/tutorial/tutorial.html
===================================================================
--- trunk/docs/tutorial/tutorial.html	2011-08-01 18:27:32 UTC (rev 4920)
+++ trunk/docs/tutorial/tutorial.html	2011-08-01 19:04:52 UTC (rev 4921)
@@ -1,1507 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
-    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<meta name="generator" content="AsciiDoc 8.5.2" />
-<title>A Swift Tutorial</title>
-<style type="text/css">
-/* Debug borders */
-p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
-/*
-  border: 1px solid red;
-*/
-}
-
-body {
-  margin: 1em 5% 1em 5%;
-}
-
-a {
-  color: blue;
-  text-decoration: underline;
-}
-a:visited {
-  color: fuchsia;
-}
-
-em {
-  font-style: italic;
-  color: navy;
-}
-
-strong {
-  font-weight: bold;
-  color: #083194;
-}
-
-tt {
-  color: navy;
-}
-
-h1, h2, h3, h4, h5, h6 {
-  color: #527bbd;
-  font-family: sans-serif;
-  margin-top: 1.2em;
-  margin-bottom: 0.5em;
-  line-height: 1.3;
-}
-
-h1, h2, h3 {
-  border-bottom: 2px solid silver;
-}
-h2 {
-  padding-top: 0.5em;
-}
-h3 {
-  float: left;
-}
-h3 + * {
-  clear: left;
-}
-
-div.sectionbody {
-  font-family: serif;
-  margin-left: 0;
-}
-
-hr {
-  border: 1px solid silver;
-}
-
-p {
-  margin-top: 0.5em;
-  margin-bottom: 0.5em;
-}
-
-ul, ol, li > p {
-  margin-top: 0;
-}
-
-pre {
-  padding: 0;
-  margin: 0;
-}
-
-span#author {
-  color: #527bbd;
-  font-family: sans-serif;
-  font-weight: bold;
-  font-size: 1.1em;
-}
-span#email {
-}
-span#revnumber, span#revdate, span#revremark {
-  font-family: sans-serif;
-}
-
-div#footer {
-  font-family: sans-serif;
-  font-size: small;
-  border-top: 2px solid silver;
-  padding-top: 0.5em;
-  margin-top: 4.0em;
-}
-div#footer-text {
-  float: left;
-  padding-bottom: 0.5em;
-}
-div#footer-badges {
-  float: right;
-  padding-bottom: 0.5em;
-}
-
-div#preamble {
-  margin-top: 1.5em;
-  margin-bottom: 1.5em;
-}
-div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
-div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
-div.admonitionblock {
-  margin-top: 1.0em;
-  margin-bottom: 1.5em;
-}
-div.admonitionblock {
-  margin-top: 2.0em;
-  margin-bottom: 2.0em;
-  margin-right: 10%;
-  color: #606060;
-}
-
-div.content { /* Block element content. */
-  padding: 0;
-}
-
-/* Block element titles. */
-div.title, caption.title {
-  color: #527bbd;
-  font-family: sans-serif;
-  font-weight: bold;
-  text-align: left;
-  margin-top: 1.0em;
-  margin-bottom: 0.5em;
-}
-div.title + * {
-  margin-top: 0;
-}
-
-td div.title:first-child {
-  margin-top: 0.0em;
-}
-div.content div.title:first-child {
-  margin-top: 0.0em;
-}
-div.content + div.title {
-  margin-top: 0.0em;
-}
-
-div.sidebarblock > div.content {
-  background: #ffffee;
-  border: 1px solid silver;
-  padding: 0.5em;
-}
-
-div.listingblock > div.content {
-  border: 1px solid silver;
-  background: #f4f4f4;
-  padding: 0.5em;
-}
-
-div.quoteblock, div.verseblock {
-  padding-left: 1.0em;
-  margin-left: 1.0em;
-  margin-right: 10%;
-  border-left: 5px solid #dddddd;
-  color: #777777;
-}
-
-div.quoteblock > div.attribution {
-  padding-top: 0.5em;
-  text-align: right;
-}
-
-div.verseblock > div.content {
-  white-space: pre;
-}
-div.verseblock > div.attribution {
-  padding-top: 0.75em;
-  text-align: left;
-}
-/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
-div.verseblock + div.attribution {
-  text-align: left;
-}
-
-div.admonitionblock .icon {
-  vertical-align: top;
-  font-size: 1.1em;
-  font-weight: bold;
-  text-decoration: underline;
-  color: #527bbd;
-  padding-right: 0.5em;
-}
-div.admonitionblock td.content {
-  padding-left: 0.5em;
-  border-left: 3px solid #dddddd;
-}
-
-div.exampleblock > div.content {
-  border-left: 3px solid #dddddd;
-  padding-left: 0.5em;
-}
-
-div.imageblock div.content { padding-left: 0; }
-span.image img { border-style: none; }
-a.image:visited { color: white; }
-
-dl {
-  margin-top: 0.8em;
-  margin-bottom: 0.8em;
-}
-dt {
-  margin-top: 0.5em;
-  margin-bottom: 0;
-  font-style: normal;
-  color: navy;
-}
-dd > *:first-child {
-  margin-top: 0.1em;
-}
-
-ul, ol {
-    list-style-position: outside;
-}
-ol.arabic {
-  list-style-type: decimal;
-}
-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;
-}
-
-div.compact ul, div.compact ol,
-div.compact p, div.compact p,
-div.compact div, div.compact div {
-  margin-top: 0.1em;
-  margin-bottom: 0.1em;
-}
-
-div.tableblock > table {
-  border: 3px solid #527bbd;
-}
-thead, p.table.header {
-  font-family: sans-serif;
-  font-weight: bold;
-}
-tfoot {
-  font-weight: bold;
-}
-td > div.verse {
-  white-space: pre;
-}
-p.table {
-  margin-top: 0;
-}
-/* Because the table frame attribute is overriden by CSS in most browsers. */
-div.tableblock > table[frame="void"] {
-  border-style: none;
-}
-div.tableblock > table[frame="hsides"] {
-  border-left-style: none;
-  border-right-style: none;
-}
-div.tableblock > table[frame="vsides"] {
-  border-top-style: none;
-  border-bottom-style: none;
-}
-
-
-div.hdlist {
-  margin-top: 0.8em;
-  margin-bottom: 0.8em;
-}
-div.hdlist tr {
-  padding-bottom: 15px;
-}
-dt.hdlist1.strong, td.hdlist1.strong {
-  font-weight: bold;
-}
-td.hdlist1 {
-  vertical-align: top;
-  font-style: normal;
-  padding-right: 0.8em;
-  color: navy;
-}
-td.hdlist2 {
-  vertical-align: top;
-}
-div.hdlist.compact tr {
-  margin: 0;
-  padding-bottom: 0;
-}
-
-.comment {
-  background: yellow;
-}
-
-.footnote, .footnoteref {
-  font-size: 0.8em;
-}
-
-span.footnote, span.footnoteref {
-  vertical-align: super;
-}
-
-#footnotes {
-  margin: 20px 0 20px 0;
-  padding: 7px 0 0 0;
-}
-
-#footnotes div.footnote {
-  margin: 0 0 5px 0;
-}
-
-#footnotes hr {
-  border: none;
-  border-top: 1px solid silver;
-  height: 1px;
-  text-align: left;
-  margin-left: 0;
-  width: 20%;
-  min-width: 100px;
-}
-
-
- at media print {
-  div#footer-badges { display: none; }
-}
-
-div#toc {
-  margin-bottom: 2.5em;
-}
-
-div#toctitle {
-  color: #527bbd;
-  font-family: sans-serif;
-  font-size: 1.1em;
-  font-weight: bold;
-  margin-top: 1.0em;
-  margin-bottom: 0.1em;
-}
-
-div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
-  margin-top: 0;
-  margin-bottom: 0;
-}
-div.toclevel2 {
-  margin-left: 2em;
-  font-size: 0.9em;
-}
-div.toclevel3 {
-  margin-left: 4em;
-  font-size: 0.9em;
-}
-div.toclevel4 {
-  margin-left: 6em;
-  font-size: 0.9em;
-}
-/* Workarounds for IE6's broken and incomplete CSS2. */
-
-div.sidebar-content {
-  background: #ffffee;
-  border: 1px solid silver;
-  padding: 0.5em;
-}
-div.sidebar-title, div.image-title {
-  color: #527bbd;
-  font-family: sans-serif;
-  font-weight: bold;
-  margin-top: 0.0em;
-  margin-bottom: 0.5em;
-}
-
-div.listingblock div.content {
-  border: 1px solid silver;
-  background: #f4f4f4;
-  padding: 0.5em;
-}
-
-div.quoteblock-attribution {
-  padding-top: 0.5em;
-  text-align: right;
-}
-
-div.verseblock-content {
-  white-space: pre;
-}
-div.verseblock-attribution {
-  padding-top: 0.75em;
-  text-align: left;
-}
-
-div.exampleblock-content {
-  border-left: 3px solid #dddddd;
-  padding-left: 0.5em;
-}
-
-/* IE6 sets dynamically generated links as visited. */
-div#toc a:visited { color: blue; }
-</style>
-<script type="text/javascript">
-/*<![CDATA[*/
-window.onload = function(){asciidoc.footnotes(); asciidoc.toc(2);}
-var asciidoc = {  // Namespace.
-
-/////////////////////////////////////////////////////////////////////
-// Table Of Contents generator
-/////////////////////////////////////////////////////////////////////
-
-/* Author: Mihai Bazon, September 2002
- * http://students.infoiasi.ro/~mishoo
- *
- * Table Of Content generator
- * Version: 0.4
- *
- * Feel free to use this script under the terms of the GNU General Public
- * License, as long as you do not remove or alter this notice.
- */
-
- /* modified by Troy D. Hanson, September 2006. License: GPL */
- /* modified by Stuart Rackham, 2006, 2009. License: GPL */
-
-// toclevels = 1..4.
-toc: function (toclevels) {
-
-  function getText(el) {
-    var text = "";
-    for (var i = el.firstChild; i != null; i = i.nextSibling) {
-      if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
-        text += i.data;
-      else if (i.firstChild != null)
-        text += getText(i);
-    }
-    return text;
-  }
-
-  function TocEntry(el, text, toclevel) {
-    this.element = el;
-    this.text = text;
-    this.toclevel = toclevel;
-  }
-
-  function tocEntries(el, toclevels) {
-    var result = new Array;
-    var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
-    // Function that scans the DOM tree for header elements (the DOM2
-    // nodeIterator API would be a better technique but not supported by all
-    // browsers).
-    var iterate = function (el) {
-      for (var i = el.firstChild; i != null; i = i.nextSibling) {
-        if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
-          var mo = re.exec(i.tagName);
-          if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
-            result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
-          }
-          iterate(i);
-        }
-      }
-    }
-    iterate(el);
-    return result;
-  }
-
-  var toc = document.getElementById("toc");
-  var entries = tocEntries(document.getElementById("content"), toclevels);
-  for (var i = 0; i < entries.length; ++i) {
-    var entry = entries[i];
-    if (entry.element.id == "")
-      entry.element.id = "_toc_" + i;
-    var a = document.createElement("a");
-    a.href = "#" + entry.element.id;
-    a.appendChild(document.createTextNode(entry.text));
-    var div = document.createElement("div");
-    div.appendChild(a);
-    div.className = "toclevel" + entry.toclevel;
-    toc.appendChild(div);
-  }
-  if (entries.length == 0)
-    toc.parentNode.removeChild(toc);
-},
-
-
-/////////////////////////////////////////////////////////////////////
-// Footnotes generator
-/////////////////////////////////////////////////////////////////////
-
-/* Based on footnote generation code from:
- * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
- */
-
-footnotes: function () {
-  var cont = document.getElementById("content");
-  var noteholder = document.getElementById("footnotes");
-  var spans = cont.getElementsByTagName("span");
-  var refs = {};
-  var n = 0;
-  for (i=0; i<spans.length; i++) {
-    if (spans[i].className == "footnote") {
-      n++;
-      // Use [\s\S] in place of . so multi-line matches work.
-      // Because JavaScript has no s (dotall) regex flag.
-      note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
-      noteholder.innerHTML +=
-        "<div class='footnote' id='_footnote_" + n + "'>" +
-        "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
-        n + "</a>. " + note + "</div>";
-      spans[i].innerHTML =
-        "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
-        "' title='View footnote' class='footnote'>" + n + "</a>]";
-      var id =spans[i].getAttribute("id");
-      if (id != null) refs["#"+id] = n;
-    }
-  }
-  if (n == 0)
-    noteholder.parentNode.removeChild(noteholder);
-  else {
-    // Process footnoterefs.
-    for (i=0; i<spans.length; i++) {
-      if (spans[i].className == "footnoteref") {
-        var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
-        href = href.match(/#.*/)[0];  // Because IE return full URL.
-        n = refs[href];
-        spans[i].innerHTML =
-          "[<a href='#_footnote_" + n +
-          "' title='View footnote' class='footnote'>" + n + "</a>]";
-      }
-    }
-  }
-}
-
-}
-/*]]>*/
-</script>
-</head>
-<body style="max-width:750px">
-<div id="header">
-<h1>A Swift Tutorial</h1>
-<div id="toc">
-  <div id="toctitle">Table of Contents</div>
-  <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
-</div>
-</div>
-<div id="content">
-<h2 id="_introduction">1. Introduction</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>This is an introductory tutorial describing the use of Swift and its programming
-language SwiftScript. It is intended to introduce new users to the basics of Swift.
-It is structured as a series of simple exercises/examples which you can
-try for yourself as you read along.</p></div>
-<div class="paragraph"><p>For information on getting an installation of Swift running, consult the
-<a href="http://www.ci.uchicago.edu/swift/guides/quickstartguide.php">Swift Quickstart Guide</a>. We advise you to install the latest stable release of Swift.
-Return to this document when you have successfully run the test SwiftScript program mentioned there.</p></div>
-<div class="paragraph"><p>There is also a
-<a href="http://www.ci.uchicago.edu/swift/guides/trunk/userguide/userguide.html">Swift User Guide</a>
-which contains a more detailed reference material on topics covered in this manual. All
-of the programs included in this tutorial can be found in your Swift
-distribution in the examples/tutorial directory.</p></div>
-</div>
-<h2 id="_hello_world">2. Hello World</h2>
-<div class="sectionbody">
-<div class="paragraph"><p>The first example program, hello.swift, outputs a hello world message
-into a file called hello.txt.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">hello.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-
-app (messagefile t) greeting() {
-    echo "Hello, world!" stdout=@filename(t);
-}
-
-messagefile outfile <"hello.txt">;
-
-outfile = greeting();</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>To run hello.swift, change directories to the location of the script
-and run the swift command as follows.</p></div>
-<div class="admonitionblock">
-<table><tr>
-<td class="icon">
-<img src="./images/icons/tip.png" alt="Tip" />
-</td>
-<td class="content">Make sure the bin directory of your swift installation is in your PATH.</td>
-</tr></table>
-</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ cd examples/tutorial
-$ swift hello.swift
-Swift svn swift-r3334 (swift modified locally) cog-r2752
-
-RunID: 20100526-1925-8zjupq1b
-Progress:
-Final status:  Finished successfully:1
-$ cat hello.txt
-Hello, world!</tt></pre>
-</div></div>
-<div class="paragraph"><p>The basic structure of this program is a type definition, an
-application procedure definition, a variable definition and then a
-call to the procedure.</p></div>
-<div class="paragraph"><p>First we define a new type, called messagefile. In this example, we will
-use this messagefile type for our output message.</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;</tt></pre>
-</div></div>
-<div class="paragraph"><p>All data in SwiftScript must be typed, whether it is stored in memory or
-on disk. This example defines a very simple type. Later on we will see
-more complex type examples.</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>app (messagefile t) greeting() {
-    echo "Hello, world!" stdout=@filename(t);
-}</tt></pre>
-</div></div>
-<div class="paragraph"><p>Next we define a procedure called greeting. This procedure will write
-out the "hello world" message to a file. To achieve this, it executes
-the unix utility <em>echo</em> with a parameter "Hello, world!" and directs
-the standard output into the output file.</p></div>
-<div class="paragraph"><p>The actual file to use is specified by the return parameter, t.</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>messagefile outfile <"hello.txt">;</tt></pre>
-</div></div>
-<div class="paragraph"><p>Here we define a variable called outfile. The type of this variable is
-messagefile, and we specify that the contents of this variable will be
-stored on disk in a file called hello.txt</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>app (messagefile t) greeting() {
-    echo "Hello, world!" stdout=@filename(t);
-}</tt></pre>
-</div></div>
-<div class="paragraph"><p>Now we call the greeting procedure, with its output going to the outfile
-variable and therefore to hello.txt on disk.</p></div>
-<div class="paragraph"><p>Over the following exercises, we’ll extend this simple hello world
-program to demonstrate various features of Swift.</p></div>
-</div>
-<h2 id="_language_features">3. Language features</h2>
-<div class="sectionbody">
-<h3 id="_parameters">3.1. Parameters</h3><div style="clear:left"></div>
-<div class="paragraph"><p>Procedures can have parameters. Input parameters specify inputs to the
-procedure and output parameters specify outputs. Our hello world greeting
-procedure already uses an output parameter, t, which indicates where the
-greeting output will go. In this section, we will modify the previous
-script to add an input parameter to the greeting function.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">parameter.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-
-app (messagefile t) greeting (string s) {
-    echo s stdout=@filename(t);
-}
-
-messagefile outfile <"parameter.hello.txt">;
-outfile = greeting("hello world");</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>We have modified the signature of the greeting procedure to indicate
-that it takes a single parameter, s, of type <em>string</em>.</p></div>
-<div class="paragraph"><p>We have modified the invocation of the <em>echo</em> utility so that it takes
-the value of s as a parameter, instead of the string literal "Hello,
-world!".</p></div>
-<div class="paragraph"><p>We have modified the output file definition to point to a different file
-on disk.</p></div>
-<div class="paragraph"><p>We have modified the invocation of greeting so that a greeting string is
-supplied.</p></div>
-<div class="paragraph"><p>The code for this section can be found in parameter.swift. It can be
-invoked using the swift command, with output appearing in parameter.hello.txt:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ swift parameter.swift</tt></pre>
-</div></div>
-<div class="paragraph"><p>Now that we can choose our greeting text, we can call the same procedure
-with different parameters to generate several output files with
-different greetings. The code is in manyparam.swift and can be run as
-before using the swift command.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">manyparam.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-
-app (messagefile t) greeting (string s) {
-    echo s stdout=@filename(t);
-}
-
-messagefile english <"manyparam.english.txt">;
-messagefile french <"manyparam.french.txt">;
-messagefile japanese <"manyparam.japanese.txt">;
-
-english = greeting("hello");
-french = greeting("bonjour");
-japanese = greeting("konnichiwa");</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>Note that we can intermingle definitions of variables with invocations
-of procedures.</p></div>
-<div class="paragraph"><p>When this program runs, there should be three new files in the
-working directory (manyparam.english.txt, manyparam.francais.txt
-and manyparam.nihongo.txt) each containing a greeting in a different
-language.</p></div>
-<div class="paragraph"><p>In addition to specifying parameters positionally, parameters can be
-named, and if desired a default value can be specified.</p></div>
-<h3 id="_adding_another_application">3.2. Adding another application</h3><div style="clear:left"></div>
-<div class="paragraph"><p>Now we’ll define a new application procedure. The procedure we define
-will capitalise all the words in the input file.</p></div>
-<div class="paragraph"><p>To do this, we’ll use the unix tr (translate) utility. Here is an
-example of using tr on the unix command line, not using Swift:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ echo hello | tr '[a-z]' '[A-Z]'
-HELLO</tt></pre>
-</div></div>
-<div class="paragraph"><p>There are two main steps - updating the transformation catalog, and
-updating the application block.</p></div>
-<div class="paragraph"><p>The transformation catalog lists where application executables are located on
-remote sites. We need to modify the transformation catalog to define a logical
-transformation for the tr utility. The transformation catalog can be found
-in etc/tc.data. There are already several entries specifying
-where executables can be found. Add a new line to the file, specifying
-where tr can be found (usually in /usr/bin/tr but it may differ on
-your system), like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>localhost       tr      /usr/bin/tr     INSTALLED       INTEL32::LINUX  null</tt></pre>
-</div></div>
-<div class="paragraph"><p>For now, ignore all of the fields except the second and the third. The
-second field tr specifies a logical application name and the third
-specifies the location of the application executable.</p></div>
-<div class="paragraph"><p>Now that we have defined where to find tr, we can use it in SwiftScript.</p></div>
-<div class="paragraph"><p>We can define a new procedure, capitalise, which calls tr.</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>app (messagefile o) capitalise(messagefile i) {
-    tr "[a-z]" "[A-Z]" stdin=@filename(i) stdout=@filename(o);
-}</tt></pre>
-</div></div>
-<div class="paragraph"><p>We can call capitalise like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>messagefile final <"capitalise.2.txt">;
-hellofile = greeting("hello from Swift");
-final = capitalise(hellofile);</tt></pre>
-</div></div>
-<div class="paragraph"><p>Here is the full program based on this exercise:</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">capitalise.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-
-app (messagefile t) greeting (string s) {
-    echo s stdout=@filename(t);
-}
-
-app (messagefile o) capitalise(messagefile i) {
-    tr "[a-z]" "[A-Z]" stdin=@filename(i) stdout=@filename(o);
-}
-
-messagefile hellofile <"capitalise.1.txt">;
-messagefile final <"capitalise.2.txt">;
-hellofile = greeting("hello from Swift");
-final = capitalise(hellofile);</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>Next, run swift and verify the output is correct.</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ swift capitalise.swift
-...
-$ cat capitalise.2.txt
-HELLO FROM SWIFT</tt></pre>
-</div></div>
-<h3 id="_anonymous_files">3.3. Anonymous files</h3><div style="clear:left"></div>
-<div class="paragraph"><p>In the previous section, the file hello.txt is used only to store
-an intermediate result. We don’t really care about which name is used
-for the file, and we can let Swift choose the name.</p></div>
-<div class="paragraph"><p>To do that, omit the mapping entirely when declaring hellofile:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>messagefile hellofile;</tt></pre>
-</div></div>
-<div class="paragraph"><p>Swift will choose a filename, which in the present version will be in a
-subdirectory called _concurrent.</p></div>
-<h3 id="_datatypes">3.4. Datatypes</h3><div style="clear:left"></div>
-<div class="paragraph"><p>All data in variables and files has a data type. So far, we’ve seen two
-types:</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-string - this is a built-in type for storing strings of text in
-      memory, much like in other programming languages
-</p>
-</li>
-<li>
-<p>
-messagefile - this is a user-defined type used to mark disc resident files as
-      containing messages
-</p>
-</li>
-</ul></div>
-<div class="paragraph"><p>SwiftScript has the additional built-in types: boolean, integer and
-float that function much like their counterparts in other programming
-languages.</p></div>
-<div class="paragraph"><p>It is also possible to create user defined types with more structure,
-for example:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type details {
-    string name;
-    int pies;
-}</tt></pre>
-</div></div>
-<div class="paragraph"><p>Each element of the structured type can be accessed using a . like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>person.name = "John";</tt></pre>
-</div></div>
-<div class="paragraph"><p>The following complete program, types.swift, outputs a greeting using a
-user-defined structure type to hold parameters for the message:</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">types.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-
-type details {
-    string name;
-    int pies;
-}
-
-app (messagefile t) greeting (details d) {
-    echo "Hello. Your name is" d.name "and you have eaten" d.pies "pies." stdout=@filename(t);
-}
-
-details person;
-
-person.name = "John";
-person.pies = 3;
-
-messagefile outfile <"types.pies.txt">;
-
-outfile = greeting(person);</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>Structured types can be comprised of marker types for files. See the
-later section on mappers for more information about this.</p></div>
-<h3 id="_arrays">3.5. Arrays</h3><div style="clear:left"></div>
-<div class="paragraph"><p>We can define arrays using the [] suffix in a variable declaration:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>string words[] = ["how","are","you"];</tt></pre>
-</div></div>
-<div class="paragraph"><p>This program, arrays.swift, will declare an array of message files.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">arrays.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-
-app (messagefile t) greeting (string s[]) {
-     echo s[0] s[1] s[2] stdout=@filename(t);
-}
-
-messagefile outfile <"arrays.txt">;
-
-string words[] = ["how","are","you"];
-
-outfile = greeting(words);</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>Observe that the type of the parameter to greeting is now an array of
-strings, string s[], instead of a single string, string s, that
-elements of the array can be referenced numerically, for example s[0],
-and that the array is initialised using an array literal,
-["how","are","you"].</p></div>
-<h3 id="_mappers">3.6. Mappers</h3><div style="clear:left"></div>
-<div class="paragraph"><p>A significant difference between SwiftScript and other languages is that
-data can be referred to on disk through variables in a very similar
-fashion to data in memory. For example, in the above examples we have
-seen a variable definition like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>messagefile outfile <"arrays.txt">;</tt></pre>
-</div></div>
-<div class="paragraph"><p>This means that outfile is a dataset variable, which is mapped to a
-file on disk called arrays.txt. This variable can be assigned to
-using = in a similar fashion to an in-memory variable. We can say that
-outfile is mapped onto the disk file arrays.txt by a mapper.</p></div>
-<div class="paragraph"><p>There are various ways of mapping in SwiftScript. Two forms of mapping,
-simple named mapping and anonymous mapping, have already
-been seen in this tutorial. Later exercises will introduce more forms.</p></div>
-<div class="paragraph"><p>In simple named mapping, the name of the file that a variable is mapped to
-is explictly listed.</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>messagefile outfile <"hello.txt">;</tt></pre>
-</div></div>
-<div class="paragraph"><p>This is useful when you want to explicitly name input and output files
-for your program. An example of this can be seen with <em>outfile</em> in the
-hello world exercise.</p></div>
-<div class="paragraph"><p>With anonymous mapping no name is specified in the source code. A name is
-automatically generated for the file. This is useful for intermediate
-files that are only referenced through SwiftScript.
-A variable declaration is mapped anonymously by ommitting any mapper
-definition.</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>messagefile hellofile;</tt></pre>
-</div></div>
-<div class="paragraph"><p>Later exercises will introduce other ways of mapping from disk files to
-SwiftScript variables.</p></div>
-<h4 id="_the_regexp_mapper">3.6.1. The Regexp Mapper</h4>
-<div class="paragraph"><p>In this exercise, we introduce the regexp mapper. This mapper
-transforms a string expression using a regular expression, and uses the
-result of that transformation as the filename to map.</p></div>
-<div class="paragraph"><p>regexp.swift demonstrates the use of this by placing output into a
-file that is based on the name of the input file. Our input file is
-mapped to the inputfile variable using the simple named mapper, then
-we use the regular expression mapper to map the output file. We then use
-the countwords() procedure to count the words in the input file and
-store the result in the output file. In order for the countwords()
-procedure to work correctly, add the wc utility (usually found in
-/usr/bin/wc) to tc.data.</p></div>
-<div class="paragraph"><p>The following program replaces the suffix of the input file (regexp_mapper.words.txt)
-with a new suffix (.count) to create regexp_mapper.words.count.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">regexp_mapper.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-type countfile;
-
-app (countfile t) countwords (messagefile f) {
-        wc "-w" @filename(f) stdout=@filename(t);
-}
-
-messagefile inputfile <"regexp_mapper.words.txt">;
-
-countfile c <regexp_mapper;
-            source=@inputfile,
-            match="(.*)txt",
-            transform="\\1count">;
-
-c = countwords(inputfile);</tt></pre>
-</div></div>
-</div></div>
-<h4 id="_fixed_array_mapper">3.6.2. fixed_array_mapper</h4>
-<div class="paragraph"><p>The fixed array mapper maps a list of files into an array. Each
-element of the array is mapped into one file in the specified directory.
-See fixed_array_mapper.swift below.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">fixed_array_mapper.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-type countfile;
-
-app (countfile t) countwords (messagefile f) {
-   wc "-w" @filename(f) stdout=@filename(t);
-}
-
-string inputNames = "fixed_array_mapper.1.txt fixed_array_mapper.2.txt fixed_array_mapper.3.txt";
-string outputNames = "fixed_array_mapper.1.count fixed_array_mapper.2.count fixed_array_mapper.3.count";
-
-messagefile inputfiles[] <fixed_array_mapper;files=inputNames>;
-countfile outputfiles[] <fixed_array_mapper;files=outputNames>;
-
-outputfiles[0] = countwords(inputfiles[0]);
-outputfiles[1] = countwords(inputfiles[1]);
-outputfiles[2] = countwords(inputfiles[2]);</tt></pre>
-</div></div>
-</div></div>
-<h3 id="_foreach">3.7. foreach</h3><div style="clear:left"></div>
-<div class="paragraph"><p>SwiftScript provides a control structure, foreach, to  operate on each
-element of an array in parallel.</p></div>
-<div class="paragraph"><p>In this example, we will run the previous word counting example over
-each file in an array without having to explicitly list the array
-elements. The source code for this example is in foreach.swift. This
-program uses three input files: foreach.1.txt, foreach.2.txt, and
-foreach.3.txt. After you have run the workflow, you should see that there are three
-output files: foreach.1.count, foreach.2.count and foreach.3.count, each
-containing the word count for the corresponding input file. We combine
-the use of the fixed_array_mapper and the regexp_mapper.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">foreach.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-type countfile;
-
-app (countfile t) countwords (messagefile f) {
-     wc "-w" @filename(f) stdout=@filename(t);
-}
-
-string inputNames = "foreach.1.txt foreach.2.txt foreach.3.txt";
-
-messagefile inputfiles[] <fixed_array_mapper;files=inputNames>;
-
-foreach f in inputfiles {
-  countfile c<regexp_mapper;
-            source=@f,
-            match="(.*)txt",
-            transform="\\1count">;
-  c = countwords(f);
-}</tt></pre>
-</div></div>
-</div></div>
-<h3 id="_if">3.8. If</h3><div style="clear:left"></div>
-<div class="paragraph"><p>Decisions can be made using <em>if</em>, like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>if(morning) {
-  outfile = greeting("good morning");
-} else {
-  outfile = greeting("good afternoon");
-}</tt></pre>
-</div></div>
-<div class="paragraph"><p>if.swift contains a simple example of this. Compile and run if.swift
-and see that it outputs "good morning". Changing the morning variable
-from true to false will cause the program to output "good afternoon".
-Here is the contents of the full script:</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">if.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-
-app (messagefile t) greeting (string s) {
-   echo s stdout=@filename(t);
-}
-
-messagefile outfile <"if.txt">;
-
-boolean morning = true;
-
-if(morning) {
-  outfile = greeting("good morning");
-} else {
-  outfile = greeting("good afternoon");
-}</tt></pre>
-</div></div>
-</div></div>
-<h3 id="_sequential_iteration">3.9. Sequential iteration</h3><div style="clear:left"></div>
-<div class="paragraph"><p>A serial execution of instructions can be carried out using the sequential iteration construct.</p></div>
-<div class="paragraph"><p>The following example demonstrates a simple application. Each step of
-the iteration is a string representation of the byte count of the
-previous step’s output, with iteration terminating when the byte count
-reaches zero.</p></div>
-<div class="paragraph"><p>Here’s the program:</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">sequential_iteration.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type counterfile;
-
-app (counterfile t) echo(string m) {
-    echo m stdout=@filename(t);
-}
-
-app (counterfile t) countstep(counterfile i) {
-    wcl @filename(i) @filename(t);
-}
-
-counterfile a[]  <simple_mapper;prefix="sequential_iteration.foldout">;
-
-a[0] = echo("793578934574893");
-
-iterate v {
-  a[v+1] = countstep(a[v]);
- trace("extract int value ", at extractint(a[v+1]));
-} until (@extractint(a[v+1]) <= 1);</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>Echo is the standard unix echo utility.</p></div>
-<div class="paragraph"><p><em>wcl</em> is our application code. It counts the number of bytes in the one
-file and writes that count out to another, like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ cat ../wcl
-#!/bin/bash
-echo -n $(wc -c < $1) > $2
-
-$ echo -n hello > a
-$ wcl a b
-$ cat b
-5</tt></pre>
-</div></div>
-<div class="paragraph"><p>Install the above wcl script somewhere and add a transformation catalog
-(tc) entry for it (see an example below, note that you will need to change the path in third column to the path where wcl is located on your localhost).</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>localhost wcl /home/ketan/bin/wcl  INSTALLED  INTEL32::LINUX  null</tt></pre>
-</div></div>
-<div class="paragraph"><p>Then run the example program like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ swift iterate.swift
-Swift svn swift-r3334 cog-r2752
-
-RunID: 20100526-2259-gtlz8zf4
-Progress:
-SwiftScript trace: extract int value , 16.0
-SwiftScript trace: extract int value , 2.0
-SwiftScript trace: extract int value , 1.0
-Final status:  Finished successfully:4</tt></pre>
-</div></div>
-</div>
-<h2 id="_runtime_features">4. Runtime features</h2>
-<div class="sectionbody">
-<h3 id="_visualizing_the_workflow_as_a_graph">4.1. Visualizing the workflow as a graph</h3><div style="clear:left"></div>
-<div class="paragraph"><p>When running a workflow, its possible to generate a provenance graph at
-the same time:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ swift -pgraph graph.dot first.swift
-$ dot -ograph.png -Tpng graph.dot</tt></pre>
-</div></div>
-<div class="paragraph"><p>graph.png can then be viewed using your favourite image viewer. The dot application is part of the graphViz project. More information can be found at <a href="http://www.graphviz.org">http://www.graphviz.org</a>.</p></div>
-<h3 id="_running_on_a_remote_site">4.2. Running on a remote site</h3><div style="clear:left"></div>
-<div class="paragraph"><p>As configured by default, all jobs are run locally. In the previous
-examples, we’ve invoked echo and tr executables from our SwiftScript
-program. These have been run on the local system (the same computer on
-which you ran swift). We can also make our computations run on a
-remote resource.</p></div>
-<div class="admonitionblock">
-<table><tr>
-<td class="icon">
-<img src="./images/icons/warning.png" alt="Warning" />
-</td>
-<td class="content">This example is necessarily more vague than previous ones,
-because it requires access to remote resources. You should ensure that
-you can submit a job using the globus-job-run (or globusrun-ws)
-command(s).</td>
-</tr></table>
-</div>
-<div class="paragraph"><p>We do not need to modify any SwiftScript code to run on another
-resource. Instead, we must modify another catalog, the site catalog.
-This catalog provides details of the location that applications will be
-run, with the default settings referring to the local machine. We will
-modify it to refer to a remote resource - the UC Teraport cluster. If
-you are not a UC Teraport user, you should use details of a different
-resource that you do have access to.</p></div>
-<div class="paragraph"><p>The site catalog is located in etc/sites.xml and is a relatively
-straightforward XML format file. We must modify each of the following
-three settings: gridftp (which indicates how and where data can be
-transferred to the remote resource), jobmanager (which indicates how
-applications can be run on the remote resource) and workdirectory (which
-indicates where working storage can be found on the remote resource).</p></div>
-<h3 id="_writing_a_mapper">4.3. Writing a mapper</h3><div style="clear:left"></div>
-<div class="paragraph"><p>This section will introduce writing a custom mapper so that Swift is
-able to access data files laid out in application-specific ways.</p></div>
-<div class="paragraph"><p>An application-specific mapper must take the form of a Java class that
-implements the <a href="http://www.ci.uchicago.edu/swift/javadoc/vdsk/org/griphyn/vdl/mapping/Mapper.html">Mapper
-interface</a>.</p></div>
-<div class="paragraph"><p>Usually you don’t need to implement this interface directly, because
-Swift provides a number of more concrete classes with some functionality
-already implemented.</p></div>
-<div class="paragraph"><p>The hierarchy of helper classes is:</p></div>
-<div class="paragraph"><p><a href="http://www.ci.uchicago.edu/swift/javadoc/vdsk/org/griphyn/vdl/mapping/Mapper.html">Mapper</a></p></div>
-<div class="paragraph"><p>This is the abstract interface for mappers in Swift. You must
-implement methods to provide access to mapper properties, to map from a
-SwiftScript dataset path (such as foo[1].bar) to a file name, to check
-whether a file exists. None of the default Swift mappers implement this
-interface directly - instead they use one of the following helper classes.</p></div>
-<div class="paragraph"><p><a href="http://www.ci.uchicago.edu/swift/javadoc/vdsk/org/griphyn/vdl/mapping/AbstractMapper.html">Abstract Mapper</a></p></div>
-<div class="paragraph"><p>This provides helper methods to manage mapper properties and to handle
-existance checking. Examples of mappers which use this class are:
-<a href="http://www.ci.uchicago.edu/swift/guides/userguide.php#mapper.array_mapper">Array Mapper</a>,
-<a href="http://www.ci.uchicago.edu/swift/guides/userguide.php#mapper.csv_mapper">CSV Mapper</a>,
-<a href="http://www.ci.uchicago.edu/swift/guides/userguide.php#mapper.fixed_array_mapper">Fixed Array Mapper</a>,
-<a href="http://www.ci.uchicago.edu/swift/guides/userguide.php#mapper.regexp_mapper">Regexp Mapper</a>,
-and <a href="http://www.ci.uchicago.edu/swift/guides/userguide.php#mapper.single_file_mapper">Single File Mapper</a>.</p></div>
-<div class="paragraph"><p><a href="http://www.ci.uchicago.edu/swift/javadoc/vdsk/org/griphyn/vdl/mapping/file/AbstractFileMapper.html">AbstractFileMapper</a>
-This provides a helper class for mappers which select files based on
-selecting files from a directory listing. It is necessary to write some
-helper methods that are different from the above mapper methods.
-Examples of mappers which use this class are:
-<a href="http://www.ci.uchicago.edu/swift/guides/userguide.php#mapper.simple_mapper">simple_mapper</a>,
-<a href="http://www.ci.uchicago.edu/swift/guides/userguide.php#mapper.filesys_mapper">filesys_mapper</a>,
-and the StructuredRegularExpressionMapper.</p></div>
-<div class="paragraph"><p>In general, to write a mapper, choose either the AbstractMapper or the
-AbstractFileMapper and extend those. If your mapper will generally
-select the files it returns based on a directory listing and will
-convert paths to filenames using some regular conversion (for example,
-in the way that simple_mapper maps files in a directory that match a
-particular pattern), then you should probably use the
-AbstractFileMapper. If your mapper will produce a list of files in some
-other way (for example, in the way that csv_mapper maps based on
-filenames given in a CSV file rather than looking at which files are in
-a directory), then you should probably use the AbstractMapper.</p></div>
-<h3 id="_writing_a_very_basic_mapper">4.4. Writing a very basic mapper</h3><div style="clear:left"></div>
-<div class="paragraph"><p>In this section, we will write a very basic (almost useless) mapper that
-will map a SwiftScript dataset into a hardcoded file called
-myfile.txt, like this:</p></div>
-<div class="literalblock">
-<div class="content">
-<pre><tt>Swift variable                            Filename</tt></pre>
-</div></div>
-<div class="literalblock">
-<div class="content">
-<pre><tt>var   <----------------------------->    myfile.txt</tt></pre>
-</div></div>
-<div class="paragraph"><p>We should be able to use the mapper we write in a SwiftScript program
-like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type file;
-file f <my_first_mapper>;</tt></pre>
-</div></div>
-<div class="paragraph"><p>First we must choose a base class - AbstractMapper or
-AbstractFileMapper. We aren’t going to use a directory listing to decide
-on our mapping - we are getting the mapping from some other source (in
-fact, it will be hard coded). So we will use AbstractMapper.</p></div>
-<div class="paragraph"><p>So now onto the source code. We must define a subclass of AbstractMapper
-and implement several mapper methods: isStatic, existing, and map. These
-methods are documented in the javadoc for the Mapper interface.</p></div>
-<div class="paragraph"><p>Here is the code implementing this mapper. Put this in your source
-vdsk directory, make a directory src/tutorial/|and put this file in
-src/tutorial/MyFirstMapper.java.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">MyFirstMapper.java</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>package tutorial;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-
-import org.griphyn.vdl.mapping.AbsFile;
-import org.griphyn.vdl.mapping.AbstractMapper;
-import org.griphyn.vdl.mapping.Path;
-import org.griphyn.vdl.mapping.PhysicalFormat;
-
-public class MyFirstMapper extends AbstractMapper {
-
-  AbsFile myfile = new AbsFile("myfile.txt");
-
-  public boolean isStatic() {
-    return false;
-  }
-
-  public Collection existing() {
-    if (myfile.exists())
-      return Arrays.asList(new Path[] {Path.EMPTY_PATH});
-    else
-      return Collections.EMPTY_LIST;
-  }
-
-  public PhysicalFormat map(Path p) {
-    if(p.equals(Path.EMPTY_PATH))
-      return myfile;
-    else
-      return null;
-  }
-}</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>Now we need to inform the Swift engine about the existence of this
-mapper. We do that by editing the MapperFactory class definition, in
-src/org/griphyn/vdl/mapping/MapperFactory.java and adding a
-registerMapper call alongside the existing registerMapper calls, like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>registerMapper("my_first_mapper", tutorial.MyFirstMapper.class);</tt></pre>
-</div></div>
-<div class="paragraph"><p>The first parameter is the name of the mapper that will be used in
-SwiftScript program. The second parameter is the new Mapper class that
-we just wrote.</p></div>
-<div class="paragraph"><p>Now rebuild Swift using the "ant redist" target.</p></div>
-<div class="paragraph"><p>This new Swift build will be aware of your new mapper. We can test it
-out with a hello world program:</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">my_first_mapper.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type messagefile;
-
-app (messagefile t) greeting() {
-        echo "hello" stdout=@filename(t);
-}
-
-messagefile outfile <my_first_mapper>;
-
-outfile = greeting();</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>Run this program, and hopefully you will find the "hello" string has
-been output into the hard coded output file myfile.txt:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ cat myfile.txt
-hello</tt></pre>
-</div></div>
-<div class="paragraph"><p>So that’s a first very simple mapper implemented. Compare the source
-code to the single_file_mapper in
-<a href="http://www.ci.uchicago.edu/trac/swift/browser/trunk/src/org/griphyn/vdl/mapping/file/SingleFileMapper.java">SingleFileMapper.java</a>.
-There is not much more code to the single_file_mapper - mostly code to
-deal with the file parameter.</p></div>
-<h3 id="_starting_and_restarting">4.5. Starting and restarting</h3><div style="clear:left"></div>
-<div class="paragraph"><p>Now we’re going to try out the restart capabilities of Swift. We will
-make a workflow that will deliberately fail, and then we will fix the
-problem so that Swift can continue with the workflow.</p></div>
-<div class="paragraph"><p>First we have the program in working form, restart.swift.</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">restart.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type file;
-
-app (file f) touch() {
-    touch @f;
-}
-
-app (file f) processL(file inp) {
-    echo "processL" stdout=@f;
-}
-
-app (file f) processR(file inp) {
-    broken "process" stdout=@f;
-}
-
-app (file f) join(file left, file right) {
-    echo "join" @left @right stdout=@f;
-}
-
-file f = touch();
-
-file g = processL(f);
-file h = processR(f);
-
-file i = join(g,h);</tt></pre>
-</div></div>
-</div></div>
-<div class="paragraph"><p>We must define some transformation catalog entries:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>localhost   touch   /usr/bin/touch  INSTALLED   INTEL32::LINUX  null
-localhost   broken  /bin/true   INSTALLED   INTEL32::LINUX  null</tt></pre>
-</div></div>
-<div class="paragraph"><p>Now we can run the program:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ swift restart.swift
-Swift 0.9 swift-r2860 cog-r2388
-
-RunID: 20100526-1119-3kgzzi15
-Progress:
-Final status:  Finished successfully:4</tt></pre>
-</div></div>
-<div class="paragraph"><p>Four jobs run - touch, echo, broken and a final echo. (note that broken
-isn’t actually broken yet).</p></div>
-<div class="paragraph"><p>Now we will break the broken job and see what happens. Replace the
-definition in tc.data for broken with this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>localhost    broken     /bin/false   INSTALLED       INTEL32::LINUX  null</tt></pre>
-</div></div>
-<div class="paragraph"><p>Now when we run the workflow, the broken task fails:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ swift restart.swift
-
-Swift 0.9 swift-r2860 cog-r2388
-
-RunID: 20100526-1121-tssdcljg
-Progress:
-Progress:  Stage in:1  Finished successfully:2
-Execution failed:
-    Exception in broken:
-Arguments: [process]
-Host: localhost
-Directory: restart-20100526-1121-tssdcljg/jobs/1/broken-1i6ufisj
-stderr.txt:
-stdout.txt:</tt></pre>
-</div></div>
-<div class="paragraph"><p>From the output we can see that touch and the first echo completed, but
-then broken failed and so swift did not attempt to execute the final echo.</p></div>
-<div class="paragraph"><p>There will be a restart log with the same name as the RunID:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ ls *20100526-1121-tssdcljg*rlog
-restart-20100526-1121-tssdcljg.0.rlog</tt></pre>
-</div></div>
-<div class="paragraph"><p>This restart log contains enough information for swift to know which
-parts of the workflow were executed successfully.</p></div>
-<div class="paragraph"><p>We can try to rerun it immediately, like this:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ swift -resume restart-20100526-1121-tssdcljg.0.rlog restart.swift
-
-Swift 0.9 swift-r2860 cog-r2388
-
-RunID: 20100526-1125-7yx0zi6d
-Progress:
-Execution failed:
-    Exception in broken:
-Arguments: [process]
-Host: localhost
-Directory: restart-20100526-1125-7yx0zi6d/jobs/m/broken-msn1gisj
-stderr.txt:
-stdout.txt:
-
-Caused by:
-    Exit code 1</tt></pre>
-</div></div>
-<div class="paragraph"><p>Swift tried to resume the workflow by executing "broken" again. It did
-not try to run the touch or first echo jobs, because the restart log
-says that they do not need to be executed again.</p></div>
-<div class="paragraph"><p>Broken failed again, leaving the original restart log in place.</p></div>
-<div class="paragraph"><p>Now we will fix the problem with "broken" by restoring the original
-tc.data line that works.</p></div>
-<div class="paragraph"><p>Remove the existing "broken" line and replace it with the successful
-tc.data entry above:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>localhost       broken          /bin/true   INSTALLED       INTEL32::LINUX  null</tt></pre>
-</div></div>
-<div class="paragraph"><p>Now run again:</p></div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>$ swift -resume restart-20100526-1121-tssdcljg.0.rlog restart.swift
-
-Swift 0.9 swift-r2860 cog-r2388
-
-RunID: 20100526-1128-a2gfuxhg
-Progress:
-Final status:  Initializing:2  Finished successfully:2</tt></pre>
-</div></div>
-<div class="paragraph"><p>Swift tries to run "broken" again. This time it works, and so Swift
-continues on to execute the final piece of the workflow as if nothing
-had ever gone wrong.</p></div>
-</div>
-<h2 id="_bits">5. Bits</h2>
-<div class="sectionbody">
-<h3 id="_named_and_optional_parameters">5.1. Named and optional parameters</h3><div style="clear:left"></div>
-<div class="paragraph"><p>In addition to specifying parameters positionally, parameters can be
-named, and if desired a default value can be specified:</p></div>
-<div class="sidebarblock">
-<div class="sidebar-content">
-<div class="sidebar-title">default.swift</div>
-<div class="listingblock">
-<div class="content">
-<pre><tt>type file;
-
-// s has a default value
-app (file t) echo (string s="hello world") {
-        echo s stdout=@filename(t);
-}
-
-file hw1<"default.1.txt">;
-file hw2<"default.2.txt">;
-
-// procedure call using the default value
-hw1 = echo();
-
-// using a different value
-hw2 = echo(s="hello again");</tt></pre>
-</div></div>
-</div></div>
-</div>
-</div>
-<div id="footnotes"><hr /></div>
-<div id="footer">
-<div id="footer-text">
-Last updated 2011-07-19 14:47:55 CDT
-</div>
-</div>
-</body>
-</html>




More information about the Swift-commit mailing list