Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
In Glish a function definition is an expression of type function. As such, it can be assigned to a variable (or record field):
bump := function(x) x + 1assigns to bump a function that when calls applies the + operator to its argument and the constant 1.
The precedence of a function definition's body is lower than that of any Glish operator. The above example is interpreted as
bump := (function(x) x + 1)and not
bump := (function(x) x) + 1
Calls to functions are also expressions; their type is determined by the value of the given function when evaluated with the given arguments. (See Chapter 6, page , for a full discussion.)
Glish includes a number of predefined functions. (See Chapter 10, page , for a discussion of each.) A particularly useful predefined function is shell, which interprets its arguments as a Bourne shell command line and returns the output from running the command (optionally on a remote host) as a string value. For example,
csh_man := shell( "man csh" )assigns to the variable
csh_man
a string vector, each element
corresponding to one line of the ``csh" manual page, and
function lower(x) shell("tr A-Z a-z", input=x, host="cruncher")returns its argument converted to lower-case, doing the work on the remote host ``cruncher". (See § 7.8, page , for both a discussion of the different options you can use with shell and how to use shell to turn an ordinary UNIX program into a Glish client.)