misc::breakmap -- stops the
mapping currently done by maprec
Introductionmisc::breakmap() stops the recursive application of a
function to all subexpressions of an expression that misc::maprec is just working on.
Call(s)misc::breakmap()
Returnsmisc::breakmap always returns TRUE.
Related
Functions
Detailsmisc::breakmap is useful as a command inside the
procedure mapped by misc::maprec in case we know that we
are finished with our work and the remaining recursive mapping is not
necessary.
Example
1We want to know whether a given expression contains a
particular type t. As soon as we have found the first
occurence of t, we can terminate our search.
>> myfound := FALSE:
misc::maprec(hold(((23+5.0)/3+4*I)*PI), {DOM_COMPLEX}=proc() begin \
myfound := misc::breakmap(); args() end_proc) :
myfound; delete myfound :
TRUE
What did we do? We told misc::maprec just to go down the
expression tree and look for subexpressions of type DOM_COMPLEX; and, whenever such
subexpression should be found, to apply a certain procedure to it. That
procedure stops the recursive mapping, remembers that we have found the
type we had searched for, and returns exactly its argument such that
the result returned by misc::maprec equals the input. In the
example below, we test whether our given expression contains the type
DOM_POLY.
>> myfound := FALSE:
misc::maprec(hold(((23+5.0)/3+4*I)*PI), {DOM_POLY}=proc() begin \
myfound := misc::breakmap() ; args() end_proc) :
myfound; delete myfound :
FALSE
Note that you do not need to use this method when
searching for subexpressions of a given type; calling hastype is certainly more
convenient.
breakmap