Summary ^^^^^^^ .All constants **** <>, <> **** .All functions **** <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <> **** .Functions by topic **** Trigonometric Functions:: <>, <>, <>, <>, <>, <>, <> Exponentials/Powers:: <>, <>, <>, <>, <>, <>, <> Rounding:: <>, <>, <> Other Math Functions:: <>, <>, <>, <>, <>, <>, <> Random Numbers:: <>, <>, <> Statistics:: <>, <>, <>, <>, <>, <> Conversion Functions:: <>, <>, <>, <>, <>, <>, <> String Functions:: <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <> Array Functions:: <> I/O Functions:: <>, <>, <>, <>, <>, <>, <>, <>, <>, <> Assertions:: <>, <>, <>, <>, <>, <>, <>, <>, <>, <> **** .Constants **** [[library-v2:PI]] [caption=""] .PI ==== [listing, swiftdoc] ---- global float PI; ---- The ratio of the circumference of a circle to its diameter, as accurately as can be represented by a Swift +float+. ==== [[library-v2:E]] [caption=""] .E ==== [listing, swiftdoc] ---- global float E; ---- The base of the natural logarithm, as accurately as can be represented by a Swift +float+. ==== **** .Trigonometric Functions **** [[library-v2:sin]] [caption=""] .sin ==== [listing, swiftdoc] ---- float sin(float a) ---- Returns the sine of +a+ radians. ==== [[library-v2:cos]] [caption=""] .cos ==== [listing, swiftdoc] ---- float cos(float a) ---- Returns the cosine of +a+ radians. ==== [[library-v2:tan]] [caption=""] .tan ==== [listing, swiftdoc] ---- float tan(float a) ---- Returns the tangent of +a+ radians. ==== [[library-v2:asin]] [caption=""] .asin ==== [listing, swiftdoc] ---- float asin(float x) ---- Returns the arc sine of +x+. The result is in the interval asciimath:[\[-pi/2, pi/2\]]. ==== [[library-v2:acos]] [caption=""] .acos ==== [listing, swiftdoc] ---- float acos(float x) ---- Returns the arc cosine of +x+. The result is in the interval asciimath:[\[0, pi\]] ==== [[library-v2:atan]] [caption=""] .atan ==== [listing, swiftdoc] ---- float atan(float x) ---- Returns the arc tangent of +x+. The result is in the interval asciimath:[\[-pi/2, pi/2\]]. ==== [[library-v2:atan2]] [caption=""] .atan2 ==== [listing, swiftdoc] ---- float atan2(float y, float x) ---- Returns the polar angle of a point at coordinates asciimath:[(x, y)]. The returned value is in the interval asciimath:[\[-pi, pi\]]. ==== **** .Exponentials/Powers **** [[library-v2:exp]] [caption=""] .exp ==== [listing, swiftdoc] ---- float exp(float x) ---- Returns asciimath:[e^x] ==== [[library-v2:ln]] [caption=""] .ln ==== [listing, swiftdoc] ---- float ln(float x) ---- Returns the natural logarithm of +x+. If +x+ is zero, the result is negative infinity. If +x+ is less than zero, the result is +NaN+. ==== [[library-v2:log]] [caption=""] .log ==== [listing, swiftdoc] ---- float log(float x, float b) ---- Returns the base +b+ logarithm of +x+. If +x+ is zero and +b+ is strictly positive, the result is negative infinity. If +x+ or +b+ are less than zero, the result is +NaN+. ==== [[library-v2:log10]] [caption=""] .log10 ==== [listing, swiftdoc] ---- float log10(float x) ---- Returns tbe base 10 logarithm of +x+. If +x+ is zero, the result is negative infinity. If +x+ is less than zero, the result is +NaN+. ==== [[library-v2:pow]] [caption=""] .pow ==== [listing, swiftdoc] ---- pow(float base, float exponent) ---- Returns asciimath:["base"^"exponent"]. If +base+ has a non-zero fractional part and is negative and if the exponent has a non-zero fractional part, then the result is +NaN+. ==== [[library-v2:sqrt]] [caption=""] .sqrt ==== [listing, swiftdoc] ---- sqrt(float x) ---- Returns the square root of +x+. If +x+ is less than zero, the result is +NaN+. ==== [[library-v2:cbrt]] [caption=""] .cbrt ==== [listing, swiftdoc] ---- cbrt(float x) ---- Returns the cube root of +x+. ==== **** .Rounding **** [[library-v2:ceil]] [caption=""] .ceil ==== [listing, swiftdoc] ---- float ceil(float x) ---- Returns the smallest number (closest to negative infinity) with a zero fractional part that is larger than +x+. ==== [[library-v2:floor]] [caption=""] .floor ==== [listing, swiftdoc] ---- float floor(float x) ---- Returns the largest number (closest to positive infinity) with a zero fractional part that is smaller than +x+. ==== [[library-v2:round]] [caption=""] .round ==== [listing, swiftdoc] ---- float round(float x) ---- Returns the closest number to +x+ that has a zero fractional part. If two numbers with a zero fractional part are equally close to +x+, the result is the largest of the two. ==== **** .Other Math Functions **** [[library-v2:min]] [caption=""] .min ==== [listing, swiftdoc] ---- int min(int a, int b) ---- Returns the smallest of +a+ and +b+ ==== [[library-v2:min-2]] [caption=""] .min ==== [listing, swiftdoc] ---- float min(float a, float b) ---- Returns the smallest of +a+ and +b+ ==== [[library-v2:max]] [caption=""] .max ==== [listing, swiftdoc] ---- int max(int a, int b) ---- Returns the largest of +a+ and +b+ ==== [[library-v2:max-2]] [caption=""] .max ==== [listing, swiftdoc] ---- float max(float a, float b) ---- Returns the largest of +a+ and +b+ ==== [[library-v2:abs]] [caption=""] .abs ==== [listing, swiftdoc] ---- int abs(int z) ---- Returns the absolute value of +z+ ==== [[library-v2:abs-2]] [caption=""] .abs ==== [listing, swiftdoc] ---- float abs(float z) ---- Returns the absolute value of +z+ ==== [[library-v2:isNaN]] [caption=""] .isNaN ==== [listing, swiftdoc] ---- boolean isNaN(float x) ---- Returns true if +x+ is +NaN+. Please note that if some +float+ variable +x+ contains a +NaN+, then +x == x+ is +false+. ==== **** .Random Numbers **** [[library-v2:randomInt]] [caption=""] .randomInt ==== [listing, swiftdoc] ---- int randomInt(int seed, int sequenceNum, int min, int max) ---- Returns a uniformly distributed random +integer+ in the interval asciimath:[\["min", "max"\]]. Each value of +seed+ generates a set of random integers, and +sequenceNum+ indexes this set. The value of +sequenceNum+ does not need to be positive. Swift guarantees that for a given version of the runtime, and a given set of parameters (+seed+, +sequenceNum+, +min+, +max+), the result of invoking this function will be the same. ==== [[library-v2:randomFloat]] [caption=""] .randomFloat ==== [listing, swiftdoc] ---- float randomFloat(int seed, int sequenceNum, float min, float max) ---- Returns a uniformly distributed random +float+ in the interval asciimath:[\["min", "max"\]]. Each value of +seed+ generates a set of random numbers, and +sequenceNum+ indexes this set. The value of +sequenceNum+ does not need to be positive. Swift guarantees that for a given version of the runtime, and a given set of parameters (+seed+, +sequenceNum+, +min+, +max+), the result of invoking this function will be the same. ==== [[library-v2:randomGaussian]] [caption=""] .randomGaussian ==== [listing, swiftdoc] ---- float randomGaussian(int seed, int sequenceNum) ---- Returns a normally distributed +float+ with zero mean and variance equal to one. Each value of +seed+ generates a set of random numbers, and +sequenceNum+ indexes this set. The value of +sequenceNum+ does not need to be positive. Swift guarantees that for a given version of the runtime, and a given set of parameters (i.e. +seed+, +sequenceNum+), the result of invoking this function will be the same. ==== **** .Statistics **** [[library-v2:sum]] [caption=""] .sum ==== [listing, swiftdoc] ---- int sum(int[] a) ---- Returns the sum of all the items in the array +a+ ==== [[library-v2:sum-2]] [caption=""] .sum ==== [listing, swiftdoc] ---- float sum(float[] a) ---- Returns the sum of all the items in the array +a+ ==== [[library-v2:avg]] [caption=""] .avg ==== [listing, swiftdoc] ---- float avg(int[] a) ---- Returns the average of all the items in the array +a+ ==== [[library-v2:avg-2]] [caption=""] .avg ==== [listing, swiftdoc] ---- float avg(float[] a) ---- Returns the average of all the items in the array +a+ ==== [[library-v2:moment]] [caption=""] .moment ==== [listing, swiftdoc] ---- float moment(int[] a, int n, float center) ---- Returns the n-th moment of the items in array +a+ about the +center+. The n-th moment is defined as asciimath:[1/("length"(a)) sum_i (a\[i\] - "center")^n] ==== [[library-v2:moment-2]] [caption=""] .moment ==== [listing, swiftdoc] ---- float moment(float[] a, int n, float center) ---- Returns the n-th moment of the items in array +a+ about the +center+. The n-th moment is defined as asciimath:[1/("length"(a)) sum_i (a\[i\] - "center")^n] ==== **** .Conversion Functions **** [[library-v2:toInt]] [caption=""] .toInt ==== [listing, swiftdoc] ---- int toInt(float x) ---- Converts a +float+ to an +int+ rounding up. In other words, it returns the integer value that is closest to +x+. If there are two integer values that are equally close to +x+, +toInt+ returns the largest fo them. ==== [[library-v2:toFloat]] [caption=""] .toFloat ==== [listing, swiftdoc] ---- float toFloat(int z) ---- Converts an +int+ to a +float+ ==== [[library-v2:parseInt]] [caption=""] .parseInt ==== [listing, swiftdoc] ---- int parseInt(string s, int base = 10) ---- Converts the string +s+ considered to be expressed in base +base+ to an integer. If the +base+ is less than two, it returns an error. If +s+ cannot be correctly interpreted as an integer in the given base, +parseInt+ returns an error. ==== [[library-v2:parseFloat]] [caption=""] .parseFloat ==== [listing, swiftdoc] ---- float parseFloat(string s) ---- Converts the string +s+ into a +float+. If +s+ does not hold a valid representation of a floating point number, +parseFloat+ returns an error. ==== [[library-v2:toString]] [caption=""] .toString ==== [listing, swiftdoc] ---- string toString(int z) ---- Returns the +string+ representation of the integer +z+ ==== [[library-v2:toString-2]] [caption=""] .toString ==== [listing, swiftdoc] ---- string toString(float x) ---- Returns the +string+ representation of the floating point number +x+ ==== [[library-v2:toString-3]] [caption=""] .toString ==== [listing, swiftdoc] ---- string toString(boolean b) ---- Returns +"false"+ if +b+ is +false+ and +"true"+ otherwise. ==== **** .String Functions **** For all the string functions, the indices are zero-based. That is, the first character in a string is located at index zero. [[library-v2:strcat]] [caption=""] .strcat ==== [listing, swiftdoc] ---- string strcat(any... s) ---- Returns a string formed by concatenating all of the parameters. The parameters that are not already strings are converted to strings. Example: [listing, swift] ---- string result = strcat("One", "Two", 3); <1> ---- <1> +result+ is the string +"OneTwo3"+ ==== [[library-v2:length]] [caption=""] .length ==== [listing, swiftdoc] ---- int length(string s) ---- Returns the number of characters in the string +s+ ==== [[library-v2:split]] [caption=""] .split ==== [listing, swiftdoc] ---- string[] split(string s, string delimiter) ---- Splits the string +s+ around +delimiter+. The delimiter is a plain string. If the delimiter cannot be found in +s+, it returns an array with a single item equal to +s+. Consecutive delimiters are merged (i.e. treated as a single delimiter). ==== [[library-v2:split-2]] [caption=""] .split ==== [listing, swiftdoc] ---- string[] split(string s, string delimiter, int maxSplit) ---- Like +split+ above, except that the splitting stops when the result reaches +maxSplit+ items, in which case the last item in the result will contain the entire remaining part of +s+. If +maxSplit+ is one or less, it returns an array of size one with the sole item containing the entire string +s+. ==== [[library-v2:splitRe]] [caption=""] .splitRe ==== [listing, swiftdoc] ---- string[] splitRe(string s, string regexp) ---- Splits +s+ around matches of the regular expression +regexp+ and returns the resulting array. If +regexp+ cannot be found in +s+, +splitRe+ returns an array of length one containing the entire string +s+. Consecutive delimiters are not explicitly merged, but the regular expression can contain quantifiers that control this behaviour. ==== [[library-v2:splitRe-2]] [caption=""] .splitRe ==== [listing, swiftdoc] ---- string[] splitRe(string s, string regexp, int maxSplit) ---- Like +splitRe+ above, except that the splitting stops when the result reaches +maxSplit+ items, in which case the last item in the result will contain the entire remaining part of +s+. If +maxSplit+ is one or less, it returns an array of size one with the sole item containing the entire string +s+. ==== [[library-v2:trim]] [caption=""] .trim ==== [listing, swiftdoc] ---- string trim(string s) ---- Returns a copy of +s+ with leading and trailing whitespace removed. ==== [[library-v2:substring]] [caption=""] .substring ==== [listing, swiftdoc] ---- string substring(string s, int start) ---- Returns a substring of +s+ starting at index +start+ (inclusive) and continuing until the end of +s+. If +start+ is negative or equal to or larger than the length of +s+, +substring+ returns an error. ==== [[library-v2:substring-2]] [caption=""] .substring ==== [listing, swiftdoc] ---- string substring(string s, int start, int end) ---- Returns a substring of +s+ starting at index +start+ (inclusive) and ending at +end+ (exclusive). If +start+ or +end+ are negative, the result is an error. If +start+ is greater or equal than +end+, the result is an error. If +end+ is greater or equal than the length of +s+, the result is an error. ==== [[library-v2:toUpper]] [caption=""] .toUpper ==== [listing, swiftdoc] ---- string toUpper(string s) ---- Returns a copy of +s+ with all lower case characters replaced by the corresponding upper case characters. ==== [[library-v2:toLower]] [caption=""] .toLower ==== [listing, swiftdoc] ---- string toLower(string s) ---- Returns a copy of +s+ with all upper case characters replaced by the corresponding lower case characters. ==== [[library-v2:join]] [caption=""] .join ==== [listing, swiftdoc] ---- string join(string[] sa, string delimiter) ---- Returns a string formed by concatenating all the items in the array +sa+ in the order of their indices, separaed by +delimiter+. If the length of +sa+ is zero, +join+ returns an empty string. ==== [[library-v2:replaceAll]] [caption=""] .replaceAll ==== [listing, swiftdoc] ---- string replaceAll(string s, string find, string replacement) ---- Returns a string formed by replacing all occurrences of +find+ in +s+ with +replacement+. ==== [[library-v2:replaceAll-2]] [caption=""] .replaceAll ==== [listing, swiftdoc] ---- string replaceAll(string s, string find, string replacement, int start, int end) ---- Returns a string formed by replacing all occurrences of +find+ in +s+ with +replacement+. The searches are only performed in the region of +s+ contained between +start+ (inclusive) and +end+ (exclusive) ==== [[library-v2:replaceAllRe]] [caption=""] .replaceAllRe ==== [listing, swiftdoc] ---- string replaceAllRe(string s, string findRe, string replacementRe) ---- Returns a string formed by replacing all matches of +findRe+ in +s+ by +replacementRe+. The +replacementRe+ can contain references to capture groups in +findRe+. References are introduced using the dollar sign (+$+) and can either be named references (e.g., +${groupName}+) or positional (e.g. $1, $2, etc.). A literal dollar sign can be inserted in the replacement string by escaping it with a backslash: "\\$". ==== [[library-v2:replaceAllRe-2]] [caption=""] .replaceAllRe ==== [listing, swiftdoc] ---- string replaceAllRe(string s, string findRe, string replacementRe, int start, int end) ---- Like +replaceAllRe+ above, except only search for +findRe+ in the region of +s+ between +start+ (inclusive) and +end+ (exclusive). ==== [[library-v2:indexOf]] [caption=""] .indexOf ==== [listing, swiftdoc] ---- int indexOf(string s, string find, int start) ---- Searches for the first occurrence of +find+ in +s+, starting at index +start+. If +find+ is not found in +s+, +indexOf+ returns +-1+. If +start+ is less than zero or greater or equal to the length of +s+, an error is returned. ==== [[library-v2:indexOf-2]] [caption=""] .indexOf ==== [listing, swiftdoc] ---- int indexOf(string s, string find, int start, int end) ---- Searches for the first occurrence of +find+ in a region of +s+ starting at index +start+ (inclusive) and ending at index +end+ (exclusive). If +find+ is not found in +s+, +indexOf+ returns +-1+. If +start+ or +end+ are negative, the result is an error. If +start+ is greater or equal than +end+, the result is an error. If +end+ is greater or equal than the length of +s+, the result is an error. ==== [[library-v2:lastIndexOf]] [caption=""] .lastIndexOf ==== [listing, swiftdoc] ---- int lastIndexOf(string s, string find, int start) ---- Searches backwards for the last occurrence of +find+ in +s+ starting at index +start+ (inclusive) and going backwards. If +start+ is +-1+, +lastIndexOf+ starts searching at the end of the string. If the search string is not found, +lastIndexOf+ returns +-1+. If +start+ is invalid (less than zero or equal to or larger than the length of +s+), lastIndexOf returns an error. ==== [[library-v2:lastIndexOf-2]] [caption=""] .lastIndexOf ==== [listing, swiftdoc] ---- int lastIndexOf(string s, string find, int start, int end) ---- Searches backwards for the last occurrence of +find+ in +s+ starting at index +start+ (inclusive) and going backwards down to index +end+ (exclusive). If +start+ is +-1+, +lastIndexOf+ starts searching at the end of the string. If the search string is not found in the search region, +lastIndexOf+ returns +-1+. If +start+ or +end+ are invalid (less than zero or equal to or larger than the length of +s+) or if end is larger than or equal to start, lastIndexOf returns an error. ==== [[library-v2:matches]] [caption=""] .matches ==== [listing, swiftdoc] ---- boolean matches(string s, string re) ---- Returns +true+ if the string +s+ matches the regular expression +re+. ==== [[library-v2:findAllRe]] [caption=""] .findAllRe ==== [listing, swiftdoc] ---- string[] findAllRe(string s, string re) ---- Returns all capture groups that result from the search of +re+ in +s+ in an array. The first element of the array (with index zero) will contain the entire matched string. ==== **** .Array Functions **** [[library-v2:length-2]] [caption=""] .length ==== [listing, swiftdoc] ---- int length(T[K] a) ---- Returns the length of +a+, waiting for +a+ to be closed. ==== **** .I/O Functions **** [[library-v2:read]] [caption=""] .read ==== [listing, swiftdoc] ---- T read(file f, string format = "None", any[string] options = {}) ---- Reads data from +file+, which can either be a string representing a local filesystem path or a <>. The valid formats are *None*, *FieldAndValue*, *FV*, and *CSV* and are explained below. *None*:: The contents of the file is a primitive value with the following format: + -- int:::: an <> float:::: a <> boolean:::: +true+ or +false+ string:::: anything; the entire content of the file will be read into the string If the return type is a composite type (array or struct) or if the return type is a mapped type, +read()+ returns an error. The +options+ parameter is ignored. -- *FieldAndValue*:: The file is formatted as field value pairs separated by an equal sign that is optionally surrounded by whitespace. The field is the qualifying part of an <> with array keys restricted to +int+, +float+ or +string+ primitive literals. If there is no qualifying part, such as when reading a variable that is of a primitive type, the field must be the dollar sign (+$+). The allowed values are primitive literals. For example, given the following Swift program: + -- [listing, swift] ---- type struct { int a; float b; string c; boolean d; } struct[] a = read("file1.dat", format = "FieldAndValue"); int n = read("file2.dat", format = "FieldAndValue"); ---- then +file1.dat+ could consist of the following: [listing, shell] ---- [0].a = 1 [0].b = 2.3 [0].c = "Some string\n" [0].d = false ---- while +file2.dat+ could have the following contents: [listing, shell] ---- $ = 10 ---- If the return type +T+ is a mapped type or if +T+ is a type that contains fields or items that are of a mapped type, +read()+ returns an error. The +options+ parameter is ignored. -- *FV*:: An alias for *FieldAndValue* *CSV*:: The format is a variation of the Comma-separated values format. The default separator is a white space character (space or tab). Different choices can be specified using +"separator"+ key for the +options+ (e.g. +options = {"separator": ","}+). The CSV format supports the following data types: + -- +int+, +float+, +boolean+:::: The file contains a value literal +string+:::: The entire contents of the file represents a string Arrays of primitive types:::: The file contains one primitive literal on each line. If the array is an array of strings, each line represents the value of the string without quotes Structures:::: The first line represents a header that must consist of the structure field names separated by the separator. The second line is a data line consisting of value literals separated by the separator. String value literals should be double-quoted if they contain the separator. If a string literal contains a double quote character, it must appear as a sequence of two double-quotes (e.g. +"A string with ""quotes"""+). If a string literal is quoted, white space between the separator and the starting and terminating quotes is ignored. If a string literal is not quoted, then white space is significant (unless the separator is white space). Consecutive separator characters are considered to be a single separator. Structure arrays:::: The first line represents a header as above. Subsequent lines represent individual items in the array and must follow the format of the data lines in simple structures. If the return type +T+ is a mapped type or if +T+ is a type that contains fields that are of a mapped type, +read()+ returns an error. Options: separator:: A string representing characters that are considered separators. Any of the characters in the string will be treated as separators. -- ==== [[library-v2:write]] [caption=""] .write ==== [listing, swiftdoc] ---- file write(any data, string format = "None", any[string] options = {}) ---- Writes data to a file and returns a file value representing the written file. The +format+ and +options+ are as in <> ==== [[library-v2:getEnv]] [caption=""] .getEnv ==== [listing, swiftdoc] ---- getEnv(string name) ---- Returns the value of the environment variable represented by +name+. If the environment variable is not defined, +getEnv+ returns an empty string. ==== [[library-v2:trace]] [caption=""] .trace ==== [listing, swiftdoc] ---- trace(any... args) ---- Waits for all +args+ to be closed and prints a string representation of the values of each of them. ==== [[library-v2:filename]] [caption=""] .filename ==== [listing, swiftdoc] ---- string filename(any f) ---- Returns the path(s) of the file(s) that +f+ is mapped to. If +f+ is a primitive value, or if +f+ is a composite type with any mapped components, +filename()+ returns an error. If +f+ is a simple file value, then +filename+ returns one path. If +f+ is a composite type with multiple file-valued fields, +filename+ returns a space separated list of the paths of all file-valued fields in +f+. The returned path(s) can either be relative to the directory from which Swift was invoked or absolute. If used in an <>, Swift guarantees that the paths point to valid files in the application's sandbox (see <>). ==== [[library-v2:filenames]] [caption=""] .filenames ==== [listing, swiftdoc] ---- string[] filenames(any f) ---- Returns the paths of the files that +f+ is mapped to. If +f+ is a primitive value, or if +f+ is a composite type with any mapped components, +filenames()+ returns an error. If +f+ is a simple file value, then the returned array has one item. The returned path(s) can either be relative to the directory from which Swift was invoked or absolute. If used in an <>, Swift guarantees that the paths point to valid files in the application's sandbox (see <>). ==== [[library-v2:dirname]] [caption=""] .dirname ==== [listing, swiftdoc] ---- string dirname(any f) ---- Like <>, except it returns the path of the directory(ies) in which the file(s) that +f+ is mapped to reside. ==== [[library-v2:arg]] [caption=""] .arg ==== [listing, swiftdoc] ---- string arg(string argName) ---- Returns the value of the command line argument +argName+. If there is no command line argument named +argName+, +arg()+ returns an error. Named arguments to a Swift program are passed on the command line after the program name (see <>) in the following format: [listing, shell] ---- swift [--=]* ---- ==== [[library-v2:arg-2]] [caption=""] .arg ==== [listing, swiftdoc] ---- string arg(string argName, string defaultValue) ---- Returns the value of the command line argument named +argName+ as above. If there is no command line argument named +name+, +arg()+ returns the value of +defaultValue+. ==== [[library-v2:args]] [caption=""] .args ==== [listing, swiftdoc] ---- string[string] args(string format) ---- Parses a Swift program's command line arguments according to +format+ and returns an array representing the name/value pairs of the arguments. The values of the arguments are validated to conform to the types in the specification, but are left as strings. The +format+ is as follows: [listing, syntax] ---- := * := | := '[' ']' := [ ] := ('-' | '/' | '_' | '0'...'9' | 'a'...'z' | 'A...Z')+ := ' ' | '=' | ':' := '<' [ ':' ] '>' := 'int' | 'string' | 'boolean' | 'float' := ---- Optional arguments without a separator and type specification are considered to be flags. If they are present on the command line, their names will appear as keys in the returned array and their value will be set to +"true"+. Arguments with a default value are considered optional (without the need to enclose them between square brackets). If they are not present on the command line, the returned array will contain their respective default values. Example: [listing, swift] ---- string[string] args = args("-min: -max: -bins: [-normalize]"); ---- ==== **** .Assertions **** Assertions provide a mechanism to check the correctness of Swift programs. If an assertion fails, the Swift program's execution is immediately terminated and the value of the +msg+ parameter is printed on the console. [[library-v2:assert]] [caption=""] .assert ==== [listing, swiftdoc] ---- assert(boolean condition, string msg = "assertion failed") ---- Asserts that the value of +condition+ is +true+. ==== [[library-v2:assertEqual]] [caption=""] .assertEqual ==== [listing, swiftdoc] ---- assertEqual(string v1, string v2, string msg = "assertion failed") ---- Asserts that +v1+ is equal to +v2+ ==== [[library-v2:assertEqual-2]] [caption=""] .assertEqual ==== [listing, swiftdoc] ---- assertEqual(int v1, int v2, string msg = "assertion failed") ---- Asserts that +v1+ is equal to +v2+ ==== [[library-v2:assertEqual-3]] [caption=""] .assertEqual ==== [listing, swiftdoc] ---- assertEqual(boolean v1, boolean v2, string msg = "assertion failed") ---- Asserts that +v1+ is equal to +v2+ ==== [[library-v2:assertEqual-4]] [caption=""] .assertEqual ==== [listing, swiftdoc] ---- assertEqual(float v1, float v2, string msg = "assertion failed") ---- Asserts that +v1+ is exactly equal to +v2+. It may be more suitable to use <> to make approximate floating point equality assertions. ==== [[library-v2:assertAlmostEqual]] [caption=""] .assertAlmostEqual ==== [listing, swiftdoc] ---- assertAlmostEqual(float v1, float v2, float tolerance = 0.0, string msg = "assertion failed") ---- Asserts that asciimath:[|v1 - v2| <= tolerance]. ==== [[library-v2:assertLT]] [caption=""] .assertLT ==== [listing, swiftdoc] ---- assertLT(int v1, int v2, string msg = "assertion failed") ---- Asserts that +v1+ is strictly less than +v2+. ==== [[library-v2:assertLT-2]] [caption=""] .assertLT ==== [listing, swiftdoc] ---- assertLT(float v1, float v2, string msg = "assertion failed") ---- Asserts that +v1+ is strictly less than +v2+. ==== [[library-v2:assertLTE]] [caption=""] .assertLTE ==== [listing, swiftdoc] ---- assertLTE(int v1, int v2, string msg = "assertion failed") ---- Asserts that +v1+ is less than or equal to +v2+. ==== [[library-v2:assertLTE-2]] [caption=""] .assertLTE ==== [listing, swiftdoc] ---- assertLTE(float v1, float v2, string msg = "assertion failed") ---- Asserts that +v1+ is less than or equal to +v2+. ==== ****