7.2.12 effect

Syntax

(effect effect-fn [main-traversal])

Description

Execute the main traversal (if present) and then, if it succeeds, call the “effect” lambda, ignoring its output. The effect could be anything, allowing us to attach arbitrary semantics to traversals.

Note that you could also perform such effects using precaution, either before or after the traversal, which makes that approach more flexible. Yet, that approach requires the lambdas used to fulfill the traversal interface in terms of arguments and return values (See Lambdas), so it’s a little more to think about. Performing an effect along with a traversal without consideration for return values or input arguments is such a common case, and that’s why effect is provided as a convenience.

Typically, we are interested in attaching such effects to a repeated traversal so that the effect is performed at each step of the traversal as long as it succeeds.

Examples

"Print each expression until the end."

(symex-eval
 (symex-traversal
   (repeat
     (effect (lambda ()
               (print (thing-at-point 'sexp)))
             (move forward)))))

Note, again, that the lambda used in an effect accepts no arguments, and its return value is disregarded.