# Using Echo with Lexical Scoping Constructs

Posted 5 months ago
721 Views
|
3 Replies
|
0 Total Likes
|
 Hello All, I would like to use Echo to debug user-defined functions which are called up by Manipulate but have found that Manipulate suppresses the Echo. To give an example, the following works fine: echoFn[x_] := Module[{}, Table[Echo[y], {y, 1, x}] ] echoFn[10]; However, when I insert the "echoFn" inside a function with lexical scoping such as Manipulate, as expected the Echo is suppressed (see attached Notebook). echoFn[x_] := Module[{}, Table[Echo[y], {y, 1, x}] ] Manipulate[ echoFn[tmp], Control[{{tmp, 5, "tst1"}, 1, 10, 1, Appearance -> "Labeled", ImageSize -> "Small"}] ] Can anyone think of a work around for this?Many thanks. Attachments:
3 Replies
Sort By:
Posted 4 months ago
 I have found that I can reduce (not eliminate) the need to debug my functions in this way by using unit tests as part of a more test driven approach.Mathematica supports test driven approaches using a "Testing Notebook" under:File | New | Programmatic NotebookIf you would rather keep your unit tests closer to your code, you can include VerificationTestIn addition to unit tests, I also find asserts and checks useful. Thanks for the great question.
 Maybe this does what you want? DynamicModule[{tmp}, Row[{ "tst1" , Spacer[4] , Slider[ Dynamic[tmp , (tmp = #; Echo[tmp]) & ] , {1, 5, 1} , Appearance -> "Labeled", ImageSize -> "Small"] } ] ]