Consider the following expression:
Block[{Print = CopyToClipboard}, doSomething[]]
Now all calls to Print
from doSomething[]
(and all other functions it may invoke) will copy values to clipboard rather than printing them. Suppose I want to modify this expression such that all calls to Print
both copy values to clipboard and print them.
Block[{Print = (CopyToClipboard[#]; Print[#]) &}, doSomething[]]
I need something similar to the above, but which doesn't go into an infinite recursion and where the occurrence of Print
within the pure function retains its global meaning that it had before the execution entered the Block
. Is it possible?
I understand the difference between Block
and Module
, and I need to use Block
to create a dynamic (rather than lexical) scoping.