Defining new binary operators.



next up previous contents
Next: Named arguments and Up: Writing your own Previous: Writing your own

Defining new binary operators.

Had we given the bslash() function a different name, namely one of the form %anything%

it could have been used as a binary operator in expressions rather than in function form. Suppose, for example, we choose ! for the internal character. The function definition would then start as

"%!%" <- function(X, y) ... (Note the use of quote marks.) The function could then be used as X %!% y. (The backslash symbol itself is not a convenient choice as it presents special problems in this context.)

The matrix multiplication operator, %*%, and the outer product matrix operator %o% are other examples of binary operators defined in this way.



Erik Moledor
Tue Jan 31 21:02:18 EST 1995