I have Echo's buried in code all over my notebook, I'd like a flag to turn them all on or off globally.

  • Sure Unprotect[Echo];Echo=Identity would disable them, but then you can't re-enable them
  • A solution that works for all the various types of Echos (EchoName, EchoEvaluation, ...) would be nice
  • QuietEcho doesn't work because I'd have to write it add it around every blob of code
  • $\begingroup$ with Echo=., no? $\endgroup$ – Roma Lee Jan 13 at 18:32
  • $\begingroup$ sure, but how do reenable it without restarting the kernel $\endgroup$ – M.R. Jan 13 at 18:34
  • 1
    $\begingroup$ Also, you might use Echo = #& instead, since Echo can take multiple arguments. $\endgroup$ – Carl Woll Jan 13 at 18:42
  • 1
    $\begingroup$ I would advocate for a global search-and-replace of all Echo[ with myEcho in your code, then at the top assign an appropriate value to myEcho, i.e. myEcho = Echo vs. myEcho = Identity depending on what you want. The global search should be relatively safe and painless, since Echo is not a common keyword in other function names. This would also work with all other types of Echo, turning them into myEcho... versions if you wanted. $\endgroup$ – MarcoB Jan 13 at 18:45
  • 1
    $\begingroup$ @RomaLee This is likely due to Echo being one of the autoloaded symbols. Check, e.g. on a fresh kernel, this: OwnValues[Echo], you will see something like {HoldPattern[Echo] :> System`Dump`AutoLoad[Hold[Echo], Hold[Echo, EchoFunction], "Language`Echo`"] /; System`Dump`TestLoad}. So, initially, Echo has OwnValues. When you execute Echo[0] (actually, just Echo is enough), you cause that definition to run. As a result, OwnValues[Echo] get cleared, instead DownValues[Echo] get populated. When you do Echo = Identity without auto-load, you hopelessly overwrite autoload code. $\endgroup$ – Leonid Shifrin Jan 13 at 19:04

Echo has an autoload, so you need to make sure the symbol is autoloaded before you modify its values:

DisableEcho[] := (Unprotect[Echo]; Echo; Echo = #&; Protect[Echo];)

EnableEcho[] := (Unprotect[Echo]; Echo=.; Protect[Echo];)





Echo[3, "EchoLabel"]


EchoLabel 3


  • $\begingroup$ Ah, I forgot the autoload $\endgroup$ – M.R. Jan 13 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.