misc::breakmap
-- stops the
mapping currently done by maprecmisc::breakmap
() stops the recursive application of a
function to all subexpressions of an expression that misc::maprec
is just working on.
misc::breakmap()
misc::breakmap
always returns TRUE
.
misc::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.We 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