next up previous contents index
Next: Reference Expressions Up: Expressions Previous: Integer Sequence Expressions

Functions and Function Calls


    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 + 1
assigns 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 example above 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 gif, for a full discussion.

Glish includes a number of predefined functions; see Chapter 9, page gif, 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 to_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 gif, 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.  

Thu Nov 13 16:44:05 EST 1997