file: job.t package: muf status: alpha
The ]withHandlersDo{...}
operator is
the current Muq MUF surface syntax for
executing code under the control of specified
event handlers. (See section Handlers.)
(The ]withHandlerDo{...}
operator is
a synonym for ]withHandlersDo{...}
.)
The syntax is
[ event0 handler0 event1 handler1 ... | ]withHandlersDo{ ... }
where:
To prevent recursive handler disasters, when any
of the specified handlers is invoked, it is run in
a context in which the given handler bindings are
all effectively dis-established. (Handler
bindings established by other
]withHandlersDo{
statements are of
course completely unaffected by this, even if they
specify the same handler functions.)
Example: This calls a function fn
with
a handler established that counts warnings.
Since the handler then returns normally, normal
warning handling is not otherwise affected:
0 --> *warnings-seen* [ .err.warning :: { [] -> [] ! } ++ *warnings-seen* ; | ]withHandlersDo{ fn }
Example: This prints a custom message on divide by zero, then (by simply returning) lets the usual handler(s) take over:
[ .err.divisionByZero :: { [] -> [] ! } "-Real- hackers don't divide by zero!\n" , ; | ]withHandlersDo{ 1 0 / }
For a fuller discussion of events, see section Muq Events.
Go to the first, previous, next, last section, table of contents.