Previous Page Next Page Contents

misc::genassop -- generates an n-ary associative operator from a binary one

Introduction

misc::genassop(binaryop, zeroelement) generates an n-ary associative operator from the binary operator binaryop, where zeroelement is a neutral element for binaryop.

Call(s)

misc::genassop(binaryop, zeroelement)

Parameters

binaryop - a function
zeroelement - an object

Returns

misc::genassop returns a procedure f. That procedure accepts an arbitrary number of arguments of the same kind binaryop does; it returns zeroelement if it is called without argument, and its only argument if it is called with one argument; its value on n arguments is inductively defined by f(x1, ..., xn)=f(binaryop(x1,x2), x3,...,xn).

Related Functions

operator

Details

Example 1

We know that _plus is an n-ary operator anyway, but let us assume that _plus was only a binary operator. We can create an own n-ary addition as follows:

>> myplus := misc::genassop(_plus, 0)
                        proc genericAssop() ... end

Now we make myplus add some values.

>> myplus(3, 4, 8), myplus(-5), myplus() 
                                 15, -5, 0

As mentioned in the ``Details'' section, myplus returns the argument if is called with exactly one argument, and it returns the zeroelement 0 if it is called without arguments.

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000