[Swift-commit] r5748 - in trunk: docs/tutorial examples/tutorial

davidk at ci.uchicago.edu davidk at ci.uchicago.edu
Tue Apr 17 08:33:25 CDT 2012


Author: davidk
Date: 2012-04-17 08:33:25 -0500 (Tue, 17 Apr 2012)
New Revision: 5748

Modified:
   trunk/docs/tutorial/language_features
   trunk/examples/tutorial/sequential_iteration.swift
Log:
Updated sequential iteration example for tutorial


Modified: trunk/docs/tutorial/language_features
===================================================================
--- trunk/docs/tutorial/language_features	2012-04-17 13:01:00 UTC (rev 5747)
+++ trunk/docs/tutorial/language_features	2012-04-17 13:33:25 UTC (rev 5748)
@@ -335,13 +335,22 @@
 Sequential iteration
 ~~~~~~~~~~~~~~~~~~~~
 
-A serial execution of instructions can be carried out using the sequential iteration construct.
+A serial execution of instructions can be carried out using the sequential 
+iteration construct. Iterate expressions allow a block of code to be evaluated
+repeatedly, with an integer parameter sweeping upwards from 0 until a 
+termination condition holds.
 
-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.
+The general form is:
+-----
+iterate var {
+    statements;
+} until (terminationExpression);
+-----
 
+The following example demonstrates one simple application. We will use
+iterate to set the value of i from 0 to 4. We will then use i
+as an index to sequentially print the values of an array. 
+
 Here's the program:
  
 .sequential_iteration.swift
@@ -351,40 +360,17 @@
 ----
 ***************************
 
-Echo is the standard unix echo utility.
-
-_wcl_ is our application code. It counts the number of bytes in the one
-file and writes that count out to another, like this:
+You should see a result similar to this:
  
 ----
-$ cat ../wcl
-#!/bin/bash
-echo -n $(wc -c < $1) > $2
+Swift trunk swift-r5746 cog-r3370
 
-$ echo -n hello > a
-$ wcl a b
-$ cat b
-5
+RunID: 20120417-0820-g1q1m8b3
+Progress:  time: Tue, 17 Apr 2012 08:20:22 -0500
+Letter 0 is: a
+Letter 1 is: b
+Letter 2 is: c
+Letter 3 is: d
+Letter 4 is: e
+Final status: Tue, 17 Apr 2012 08:20:22 -0500
 ----
-
-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).
-
-----
-localhost wcl /home/ketan/bin/wcl  INSTALLED  INTEL32::LINUX  null
-----
-
-Then run the example program like this:
-
- 
-----
-$ 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
-----

Modified: trunk/examples/tutorial/sequential_iteration.swift
===================================================================
--- trunk/examples/tutorial/sequential_iteration.swift	2012-04-17 13:01:00 UTC (rev 5747)
+++ trunk/examples/tutorial/sequential_iteration.swift	2012-04-17 13:33:25 UTC (rev 5748)
@@ -1,18 +1,12 @@
-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);  
+
+string alphabet[];
+alphabet[0] = "a";
+alphabet[1] = "b";
+alphabet[2] = "c";
+alphabet[3] = "d";
+alphabet[4] = "e";
+
+iterate i  
+{
+   tracef("Letter %i is: %s\n", i, alphabet[i]);
+}  until(i == 5);




More information about the Swift-commit mailing list