[Swift-commit] r6257 - trunk/docs/userguide

ketan at ci.uchicago.edu ketan at ci.uchicago.edu
Mon Feb 11 11:24:41 CST 2013


Author: ketan
Date: 2013-02-11 11:24:40 -0600 (Mon, 11 Feb 2013)
New Revision: 6257

Modified:
   trunk/docs/userguide/app_procedures
   trunk/docs/userguide/language
Log:
Swift structures and readData

Modified: trunk/docs/userguide/app_procedures
===================================================================
--- trunk/docs/userguide/app_procedures	2013-02-11 02:17:16 UTC (rev 6256)
+++ trunk/docs/userguide/app_procedures	2013-02-11 17:24:40 UTC (rev 6257)
@@ -432,25 +432,17 @@
 
 readData
 ~~~~~~~~
-readData will read data from a specified file.
-
-The format of the input file is controlled by the type of the return value.
-
-For scalar return types, such as int, the specified file should contain
-a single value of that type.
-
-For arrays of scalars, the specified file should contain one value per
-line.
-
-For structs of scalars, the file should contain two rows. The first row
-should be structure member names separated by whitespace. The second row
-should be the corresponding values for each structure member, separated
-by whitespace, in the same order as the header row.
-
-For arrays of structs, the file should contain a heading row listing
-structure member names separated by whitespace. There should be one row
-for each element of the array, with structure member elements listed in
-the same order as the header row and separated by whitespace. (since
+readData will read data from a specified file and assign it to Swift variable. The format of the input file is
+controlled by the type of the return value. For scalar return types, such as
+int, the specified file should contain a single value of that type. For arrays
+of scalars, the specified file should contain one value per line.  For complex types
+of scalars, the file should contain two rows. The first row should be structure
+member names separated by whitespace. The second row should be the
+corresponding values for each structure member, separated by whitespace, in the
+same order as the header row.  For arrays of structs, the file should contain a
+heading row listing structure member names separated by whitespace. There
+should be one row for each element of the array, with structure member elements
+listed in the same order as the header row and separated by whitespace. (since
 Swift 0.4)
 
 readStructured

Modified: trunk/docs/userguide/language
===================================================================
--- trunk/docs/userguide/language	2013-02-11 02:17:16 UTC (rev 6256)
+++ trunk/docs/userguide/language	2013-02-11 17:24:40 UTC (rev 6257)
@@ -11,20 +11,52 @@
 variables. The syntax superficially resembles C and Java. For example,
 { and } characters are used to enclose blocks of statements.
 
-Types in Swift can be atomic or composite. An atomic type can be
-either a primitive type or a mapped type. Swift provides a fixed set
-of primitive types, such as integer and string. A mapped type
-indicates that the actual data does not reside in CPU addressable memory
-(as it would in conventional programming languages), but in POSIX-like
-files. Composite types are further subdivided into structures and
-arrays. Structures are similar in most respects to structure types in
-other languages. Arrays use numeric indices, but are sparse. They can
-contain elements of any type, including other array types, but all
-elements in an array must be of the same type. We often refer to
+Types in Swift can be atomic or composite. An atomic type can be either a
+primitive type or a mapped type. Swift provides a fixed set of primitive types,
+such as integer and string. A mapped type indicates that the actual data does
+not reside in CPU addressable memory (as it would in conventional programming
+languages), but in POSIX-like files. Composite types are further subdivided
+into structures and arrays. Structures are similar in most respects to
+structure types in other languages. In Swift, structures are defined using the
+_type_ keyword (there is no struct keyword). Arrays use numeric indices, but
+are sparse. They can contain elements of any type, including other array types,
+but all elements in an array must be of the same type. We often refer to
 instances of composites of mapped types as datasets.
 
 image:type-hierarchy.png[]
 
+Atomic types such as string, int, float and double work the same way as in
+C-like programming languages. A variable of such atomic types can be defined as
+follows:
+
+----
+string astring = "hello";
+----
+
+A struct variable is defined using the _type_ keyword as discussed above.
+Following is an example of a variable holding employee data:
+
+----
+type Employee{
+    string name;
+    int id;
+    string address;
+}
+----
+
+The members of the structure defined above can be accessed using the dot
+notation. An example of a variable of type Employee is as follows:
+
+----
+Employee emp;
+emp.name="Thomas";
+emp.id=2222;
+emp.address="Chicago";
+----
+
+Arrays of structures are allowed in Swift. A convenient way of populating
+structures and arrays of structures is to use the _readData()_ function.
+
 Mapped type and composite type variable declarations can be annotated
 with a mapping descriptor indicating the file(s) that make up that
 dataset. For example, the following line declares a variable named




More information about the Swift-commit mailing list