Neatware Header
Home   Products   Forums   Partners   Buy   Company   Contact   Blog   

5. Types

5.1 String

String is a primitive object of mCL. It consists of any characters. Some characters may have special meaning for a string in the context. String commands consists of a group of subcommands.

Construction

  • append v s1 s2 ... command concatenates string s1, s2, ... onto the variable v and returns the new value of the variable v.
  • join ls s command joins the elements of list s together and distinguishes them with the string s. The default string is a space.
  • split s c command splits string s with the character c.

Access

  • string length s command returns the number of characters of s.
  • string range s i j command returns the substring of the s from i to j.
  • string index s i returns the character in the position i. A string has a zero based position.
  • string first s e command returns the first occurrence of element e in the s, return 1 if nothing found.
  • string last s e command finds the last element e occurrence in the s, return 1 if nothing found.

Operation

  • string compare s1 s2 compares two strings. It returens 0 if they are equal, or -1 if s1 is less than the s2, otherwise +1.
  • string match s pattern command completes pattern matching, that is the string s matches pattern string. Pattern may be the combination of characters and the special matching characters where * for any characters, ? for any single character, and [xyz] for one of a character in the [ ]. If s matches the pat then it returns 1, otherwise it returns 0.
  • string tolower s converts the string s to lower case.
  • string toupper s converts the string s to upper case.

Format

  • format s v1 v2 ... command is similar to printf() function of C. It returns a formated string. s is the format specification. v1, v2 ... are corresponding values.

5.2 List

List is an order set of items.

Construction

  • list a1 a2 ... command constructs a list from its arguments a1, a2, and others. The curly brace {} represents empty list.
  • lappend ls a1 a2 ... command appends arguments a1, a2, ... to the the end of the list ls as elements.
  • lconcat ls1 ls2 ... joins the elements in ls1, ls2, ... together to form a new list.

Access

  • llength ls returns the number of elements in the list ls.
  • lrange ls i j command returns elements of ls from i to j.
  • lindex ls i returns the ith element of the ls.

Operation

  • lsearch ls v [option] returns the index of list ls that matches the value of variable v in one of an option or return -1 if no value is found. -glob, -exact, and -regexp are possible option values. The default option value is -exact.
  • linsert ls i e1 e2 ... command inserts elements e1, e2, ... before the index i of the list ls and returns the new list.
  • lreplace ls i j e1 e2 ... command replaces elements from i to j in ls by elements e1, e2, ... and returns the new list.
  • lsort ls [option] sorts elements in list ls according to one or more option values (-ascii, -integer, -real, -dictionary, -increasing, -decreasing, -command, -index i). The default options are '-ascii -increasing'. It returns the new list.

5.3 Array

A mCL array is acturally an associate array that is a collection of key/value pairs. The key is a index and the value is an element of an array. An element of array 'a' with index 'key' is represented as a(key). Its value is $a(key). An array is implemented as a hash table.

Construction

  • array names ary [pattern] command returns the list of an array a’s keys that match the pattern. If no pattern item it returns the list of all the keys of the array ary.

Access

  • array exists ary returns 1 if ary is an array variable, otherwise it returns 0.
  • array size ary returns the number of elements of ary.

Operation

  • array get ary [pattern] returns a key/value pair list. pattern is used for matching keys. Without pattern array get command will return all the pairs.
  • array set ary ls command sets ary with the list ls in the key/value form.

5.4. File

File commands are divided inot directory and file operations.

Directory Status

  • file dirname name returns a directory name in a path. If name is a relative file name and only contains one path element, then returns \. If name refers to a root directory, then the root directory is returned.
  • file tail name returns the name after the last directory separator. If name contains no separators then returns name itself.
  • file isdirectory name returns 1 if file name is a directory, otherwise returns 0.
  • file mkdir dir1 dir2 ... creates one or more directories. For each pathname dir specified, this command will create all non-existing parent directories as well as dir itself. If a directory exists, then no action is taken and no error is returned. Trying to overwrite an existing file with a directory will result in an error. dir arguments are processed in the order specified, halting at the first error, if any.

File Status

  • file size name returns the file size.
  • file atime name returns a decimal string giving the time at which file name was last accessed. The time is measured in the standard POSIX fashion as seconds from a fixed starting time. If the file doesn't exist or its access time cannot be queried then an error is generated.
  • file stat name varname invokes the stat kernel call on name, and uses the variable given by varname to hold information returned from the kernel call. varname is treated as an array variable, and the following elements of that variable are set: atime, ctime, dev, gid, ino, mode, mtime, nlink, size, type, uid. Each element except type is a decimal string with the value of the corresponding field from the stat return structure; see the manual entry for stat for details on the meanings of the values. The type element gives the type of the file in the same form returned by the command file type. This command returns an empty string.
  • file attributes name [option] this subcommand returns a list of the platform specific flags and their values. The file attributes name sets one or more of the values. The values are as follows:

    On Windows, -archive gives the value or sets or clears the archive attribute of the file. -hidden gives the value or sets or clears the hidden attribute of the file. -longname will expand each path element to its long version. This attribute cannot be set. -readonly gives the value or sets or clears the readonly attribute of the file. -shortname gives a string where every path element is replaced with its short (8.3) version of the name. This attribute cannot be set. -system gives or sets or clears the value of the system attribute of the file.

Operation

  • file copy source target copies source file to the target file or directory.
  • file delete pathname [-force] remove files and directories. -force option will delete the pathname in force.
  • file rename source target rename source file name to the target.
  • file join name [name ...] takes one or more file names and combines them, using the correct path separator for the current platform.
  • file split name returns a list whose elements are the path components in name. The first element of the list will have the same path type as name. All other elements will be relative.