Sprintf Prototype: String Sprintf(String format, ..., Integer n); Sprintf formats a string from 'n' objects according to 'format'. Unlike its C counterpart, Sprintf requires the number of items to format. For example. Sprintf("%f is greater than %f but %s is better than %s\n", PI, E, "Cake" "Pie", 4); The final argument to Sprintf is the number of items to format; in this case, there are 4 items. -------------------- _clear_error May be used in error blocks to clear the error that triggered the error block. Execution resumes following the statement triggering the block. -------------------- _stkdepth returns number of items on stack -------------------- acos -------------------- aget Syntax: i j ... k ARRAY aget returns ARRAY[i][j]...[k] -------------------- aput Syntax: x i j ... k ARRAY put sets ARRAY[i][j]...[k] = x -------------------- array_sort Requires an array on the stack as well as a function name to call for the comparison. The array to be placed on the stack is the array to be sorted. The routine returns an integer index array which indicates the result of the sort. The first array is unchanged. -------------------- asin -------------------- atan -------------------- autoload Prototype: Void autoload(String fun, String file); This function simply declares function 'fun' to the interpreter. When 'fun' is actually called, its actual function definition will be loaded from 'file'. Example: autoload ("bessel_j0", "/usr/lib/slang/bessel.sl"); See Also: evalfile -------------------- byte_compile_file Prototype Void byte_compile_file (String file, Integer method); byte compiles 'file' producing a new file with the same name except a 'c' is added to the output file name. For example, byte_compile_file("site.sl"); produces a new file named 'site.slc'. If 'method' is non-zero, the file is preprocessed only. Note that the resulting bytecompiled file must only be used by the executable that produced it. Set 'method' to a non-zero value to use the byte compiled file with more than one executable. -------------------- case Prototype: Integer case(a, b); This function is designed to make the switch statement look more like the C one. Basically, it does a generic compare operation. Both parameters 'a' and 'b' must be of the same type. It returns zero if their types differ or have different values. In a switch statment, it may be used as: switch (token) { case "return": return_function ();} { case "break": break_function ();} Unlike the C version, it one cannot have: switch (i) {case 10: case 20: do_ten_or_twenty (i);} One must do: switch (i) {case 10 or case (i, 20) : do_ten_or_twenty (i);} -------------------- char Prototype: String char (Integer c); This function takes and integer and returns a string of length 1 whose first character has ascii value 'c'. -------------------- chmod Prototype Integer chmod(String file, Integer mode); 'chmod' changes the permissions of 'file' to those specified by 'mode'. It returns 0 upon success, -1 if the process lacks sufficient privilege for the operation, or -2 if the file does not exist. See also: chown, stat_file -------------------- chown Prototype Integer chown(String file, Integer uid, Integer gid); Change ownership of 'file' to that of user id 'uid' and group id 'gid'. This function returns 0 upon success and a negative number up failure. It returns -1 if the process does not have sufficent privileges and -2 if the file does not exist. See also: chmod, stat_file -------------------- copy_array Prototype: Void copy_array(Array b, Array a); Copies the contents of array 'a' to array 'b'. Both arrays must be of the same type and dimension. -------------------- cos -------------------- create_array Prototype: create_array (Integer type, Integer i_1, i_2 ... i_dim, dim); Creates an array of type 'type' with dimension 'dim'. i_n is an integer which specifies the maximum size of array in direction n. 'type' is a control integer which specifies the type of the array. Types are: 's' : array of strings 'f' : array of floats 'i' : array of integers 'c' : array of characters At this point, dim cannot be larger than 3. Also note that space is dynamically allocated for the array and that copies of the array are NEVER put on the stack. Rather, references to the array are put on the stack. When the array is no longer needed, it must be freed with 'free_array' Example: variable a = create_array ('f', 10, 1); This creates a 1 dimensional array of 10 floats and assigns it to 'a' See also: free_array -------------------- define_case Two parameters are integers in the range 0 to 255. The first integer is the ascii value of the upprcase character and the 2nd integer is the value of its lowercase counterpart. For example, to define X as the uppercase of Y, do: X Y define_case -------------------- dup duplicate top object on the stack. -------------------- eval evaluate STRING as an S-Lang expression. -------------------- evalfile Prototype: Integer evalfile (String file); Load 'file' as S-Lang code. If loading is successful, a non-zero result will be returned. If the file is not found, zero will be returned. See also: eval, autoload -------------------- exp -------------------- extract_element Prototype: String extract_element (String list, Integer nth, Integer delim); Returns 'nth' element in 'list' where 'delim' separates elements of the list. 'delim' is an Ascii value. Elements are numbered from 0. For example: extract_element ("element 0, element 1, element 2", 1, ','); returns the string " element 1", whereas extract_element ("element 0, element 1, element 2", 2, ' '); returns "0,". See also: is_list_element. -------------------- float Convert from integer or string representation to floating point. For example, "12.34" float returns 12.34 to stack. as another example, consider: 1 2 / ==> 0 since 1 and 2 are integers 1 2 float / ==> 0.5 since float converts 2 to 2.0 and floating point division is used. -------------------- free_array Prototype: Void free_array (Array a); Frees up the space which array occupies. All reference to this space will now be meaningless and will generate an error. -------------------- getenv Prototype: String getenv(String var); Returns value of an environment variable 'var' as a string. The empty "" is returned if the 'var' is not defined. See also: putenv -------------------- init_char_array Prototype: Void init_char_array(Array_Type a, String s); a is an array of type 'c' (character array) and s is a string. -------------------- int returns ascii value of the first character of a string. -------------------- integer Convert from a string representation to integer. For example, "1234" integer returns 1234 to stack. -------------------- is_defined Prototype: Integer is_defined (String obj); This function is used to determine whether or not 'obj' has been defined. If 'obj' is not defined, it returns 0. Otherwise, it returns a non-zero value that defpends on the type of object 'obj' represents. Specifically: +1 if arg is an intrinsic function +2 if user defined function -1 if intrinsic variable -2 if user defined variable -------------------- is_list_element Prototype: Integer is_list_element (String list, String elem, Integer delim); If 'elem' is an element of 'list' where 'list' is a 'delim' seperated list of strings, this function returns 1 plus the matching element number. If 'elem' is not a member of the list, zero is returned. Example: is_list_element ("element 0, element 1, element 2", "0,", ' '); returns 2 since "0," is element number one of the list (numbered from zero). See also: extract_element. -------------------- is_substr Syntax: "a" "b" is_substr returns the position of "b" in "a". If "b" does not occur in "a" it returns 0--- the first position is 1 -------------------- isdigit returns TRUE if CHAR (string of length 1) is a digit. -------------------- log -------------------- log10 -------------------- lstat_file Prototype: Integer lstat_file(String file); This function is like 'stat_file' but it returns information about the link itself. See 'stat_file' for usage. See also: stat_file -------------------- make_printable_string Prototype: String make_printable_string(String str); Takes input string 'str' and creates a new string that may be used by the interpreter as an argument to the 'eval' function. The resulting string is identical to 'str' except that it is enclosed in double quotes and the backslash, newline, and double quote characters are expanded. See also: eval -------------------- polynom Usage: a b .. c n x polynom =y This computes: ax^n + bx^(n - 1) + ... c = y -------------------- pop Prototype: Void pop (); 'pop' is used to remove the top object from the S-Lang stack. It is typically used to ignore values from function that return a value. -------------------- pow -------------------- print_stack dumps tha S-Lang stack -------------------- putenv Prototype: Void putenv(String s); This functions adds string 's' to the environment. Typically, 's' should be a String of the form "name=value". It signals an error upon failure. -------------------- set_float_format Prototype: Void set_float_format (String fmt); This function is used to set the floating point format to be used when floating point numbers are printed. The routines that use this are the traceback routines and the 'string' function. The default value is "%f". -------------------- sin -------------------- slang_trace_function only argument is a string that specifies a function name that is to be traced. See also the variable _slangtrace. -------------------- slapropos -------------------- sqrt -------------------- stat_file Prototype: Integer stat_file(String file); This function returns information about 'file' through the use of the system 'stat' call. If the stat call fails, the function returns a negative integer. If it is successful, it returns zero. Upon failure it returns a negative number. To retrieve information obtained by this call, use the 'stat_struct' function. See also: lstat_file, stat_struct -------------------- stat_struct Prototype Integer stat_struct(String field); This functions returns information previously obtained by a call to the 'stat_file' or 'lstat_file' functions. The 'field' argument specifies what piece of information to return. Valid values for 'field' are: "dev" "ino" "mode" "nlink" "uid" "gid" "rdev" "size" "atime" "mtime" "ctime" See the man page for 'stat' for a discussion of these fields. The following example returns the size of the file "jed.rc": variable size; if (stat_file("jed.rc") < 0) error ("Unable to stat file!"); size = stat_struct("size"); -------------------- str_quote_string Prototype: String str_quote_string(String str, String qlis, Integer quote); Return a string identical to 'str' except that all characters in the string 'qlis' are escaped with the 'quote' character including the quote character itself. -------------------- str_uncomment_string Prototype: String str_uncomment_string(String s, String beg, String end); 'beg' and 'end' are strings whose characters define a set of comment delimeters. This function removes comments defined by the delimeter set from the input string 's' and returns it. For example, str_uncommen_string ("Hello (testing) 'example' World", "'(", "')"); returns the string: "Hello World"; This routine does not handle multicharacter comment delimeters and it assumes that comments are not nested. -------------------- strcat Prototype: String strcat(String a, String b); Conconcatenates 'a' and 'b' and returns the result. See also: Sprintf -------------------- strcmp Prototype: Integer strcmp (String a, String b); 'strcmp' performs a case sensitive comparison between two strings. It returns 0 if the strings are identical, a negative number if 'a' is less than 'b' and a positive result if 'a' is greater than 'b' (in a lexicographic sense). See also: strup, strlow -------------------- string Prototype: String string (obj); Here 'obj' can be of any type. The function 'string' will return a string representation of 'obj'. Example: string (12.34) returns "12.34" See also: Sprintf -------------------- string_match_nth Prototype: Integer Integer string_match_nth(Integer nth); This function returns 2 integers describing the result of the last call to 'string_match'. It returns both the offset into the string and the length of characters matches by the 'nth' submatch. By convention, 'nth' equal to zero means the entire match. Otherwise, 'nth' must be an integer, 1 to 9, and refers to the set of characters matched by the 'nth' regular expression given by \(...\). For example, consider: variable matched, pos, len; matched = string_match("hello world", "\\([a-z]+\\) \\([a-z]+\\)", 1); if (matched) { (pos, len) = string_match_nth(2); } This will set 'matched' to 1 since a match will be found at the first position, 'pos' to 7 since 'w' is the 7th character of the string, and len to 5 since "world" is 5 characters long. -------------------- string_match Prototype Integer string_match(String str, String pat, Integer pos); Returns 0 if 'str' does not match regular expression specified by 'pat'. This function performs the match starting at position 'pos' in 'str'. The first character of 'str' corresponds to 'pos' equal to one. This function returns the position of the start of the match. To find the exact substring actually matched, use 'string_match_nth'. See also: string_match_nth, strcmp, strncmp -------------------- strlen Prototype: Integer strlen (String a); Returns the length of 'a'. -------------------- strlow Takes a string off the stack a replaces it with all characters in lowercase. -------------------- strncmp like strcmp but takes an extra argument--- number of characters to compare. Example, "apple" "appliance" 3 strcmp --> 0 -------------------- strsub Syntax: "string" n ascii_value strsub This forces string to have a char who asciii value is ascii_val at the nth position. The first character in the string is at position 1. -------------------- strtrim Trims leading and trailing whitespace from a string. WHitespace is defined to be spaces, tabs, and newline chars. -------------------- strup Takes a string off the stack a replaces it with all characters in uppercase. -------------------- substr Syntax: "string" n len substr returns a substring with length len of string beginning at position n. -------------------- system -------------------- tan -------------------- unix_ctime Prototype: String unix_ctime(Integer secs); Returns a string representation of the time as given by 'secs' seconds since 1970. -------------------- unix_kill Prototype: Integer unix_kill(Integer pid, Integer sig); -------------------- E -------------------- PI -------------------- _slang_version -------------------- _slangtrace Prototype: Integer _slangtrace; If non-zero, begin tracing when function declared by lang_trace_function is entered. This does not trace intrinsic functions. -------------------- _traceback If non-zero, dump S-Lang tracback on error. --------------------