The operand of a procedure can be expressed either as a number or as a procedure call -- what about the other kinds of expressions? Can they be used to express operands in procedure calls?
Yes, any kind of an expression can be an argument in a procedure call, provided that the value of the expression is an operand of the appropriate type.
Are there specific grammatical rules for putting together procedure calls?
Yes. It's pretty much the way you would expect from the examples we've seen so far: A procedure call consists of a left parenthesis, a sequence of one or more expressions, and a right parenthesis. The value of the first expression must be a procedure -- the procedure that will be called -- and the other expressions are its operands. The number of operand expressions must be consistent with the arity of the procedure, and the operands must be of types that the procedure is prepared to deal with. That's all there is to it.
``The value of the first expression must be a procedure''? What does that mean?
Well, right after the left parenthesis at the beginning of a procedure
call, you have an expression such as quotient or
*. This expression has a value; the value is a procedure.
Some Scheme expressions have integer values; some, as we'll see later on,
have values that are character strings; others have values of other types. Quotient and *
have values that are procedures, so you can make either of them the first
expression in a procedure call.
So quotient names the quotient procedure, just as
15 names the integer fifteen?
Not quite in the same way. The numeral 15 is what's called a
literal; there is no way for the
programmer to change its value even if she wanted to. Sometimes literals
are called constants to emphasize the fact that you can't change
their meanings. The expression quotient is a variable. Scheme sets things up
initially so that the quotient procedure is the value of this variable, but
it also provides ways for the programmer to change that value if she
chooses.
Next topic
Previous topic
Table of contents
This document is available on the World Wide Web as
http://www.math.grin.edu/~stone/scheme-web/calls.html