Binding



next up previous contents index
Next: Method Selection Up: Expressions Previous: Procedure Invocation

Binding

A routine can have some of its arguments bound, producing another routine that expects fewer arguments. Binding is essentially an incomplete invocation (6.1): the binding arguments are treated like actuals, and matched up with formals just as in an invocation. An asterisk (*) is used as a placeholder; it indicates an argument position for which no binding is made.

The form for binding is:

bind "(" <expr> <bind_args> ")"
where
<bind_args> ->  ["," <bind_arg>]* ["," <varying_args>] 
<bind_arg> -> <expr> | "*"
The expressions are evaluated in an unspecified order. The result of the first expression must be a routine. The results of evaluating the bind_arg expressions are treated just as in an invocation (6.1), except that when the bind_arg is an asterisk, no assignment is made to the corresponding formal. The binding is legal if the right number of arguments is provided and the assignments are legal. The result of the bind expression is a new routine. The type of that routine has arguments only for the formals where an asterisk appeared. The new routine is the same kind (procedure or iterator) as the original routine, and has the same number and types of results (yielded results) and exceptions as the original.

For example, consider a procedure

p (x: int, y: char) returns (bool)
Then
q: proc (int) returns (bool) := bind(p, *, 'c')
is legal and results in a new procedure "q" with "'c'" bound to the formal "y"; "q" is invoked with a single "int" for the formal "x", which was not bound. Thus, invocation "q(5)" has identical behavior to invocation "p(5, 'c')". A bound routine can be bound again, e.g.,
r: proc ( ) returns (bool) := bind(q, 5)
produces a new procedure "r", where invocation "r( )" has identical behavior to invocation "p(5, 'c')".

Note that if varying_args are provided, the corresponding formal is bound to the newly-constructed sequence (6.1). It is not possible to extend the sequence (so that it would contain additional elements) in a subsequent bind expression or invocation.



next up previous contents index
Next: Method Selection Up: Expressions Previous: Procedure Invocation



theta-questions@lcs.mit.edu