       Re: problem writing debugging utility function

• To: mathgroup at smc.vnet.net
• Subject: [mg100308] Re: problem writing debugging utility function
• From: "dabrowsa at indiana.edu" <dabrowsa at indiana.edu>
• Date: Sun, 31 May 2009 06:37:36 -0400 (EDT)
• References: <gvq09k\$mqv\$1@smc.vnet.net>

```Thanks a lot to Leonid, Szabolcs, and Ken for their solutions.  I
liked Leonid's the best, being both much simpler and more general than
mine.

SetAttributes[ShowIt, HoldAll];
ShowIt[code_] :=
Module[{y},
Print[ToString[Unevaluated[code]], " = ", y = code];
y];

My own solution was the hideous

[{"\""<>var<>" = "<>"\"",",",var}],"]"}}]&;

which makes dbgv work like a macro.  The grotesqueness is because what
\$PreRead sees is a very raw input form, with expressions broken down
into RowBox's.  In a sense this is the most direct analog to Lisp's
macros, but ... yechh.

I never fully grokked the distinction between it and Hold[].  In fact
I'm still a bit confused about it.  At first I thought it might like
the evaluation inhibitor ` in Lisp, but some examples disabused me of
that.

In:= f@Unevaluated[5 + 6 + 7 + 8]

Out= f[Unevaluated[5 + 6 + 7 + 8]]

In:= ToString@Unevaluated[5 + 6 + 7 + 8]

Out= "5 + 6 + 7 + 8"

I might have expected Out= "Unevaluated[5 + 6 + 7 + 8]"

In:= sqr[x_] := x^2

In:= sqr@Unevaluated[5 + 6 + 7 + 8]

Out= 676

I might have expected Out= sqr[5 + 6 + 7 + 8] since sqr does not
know what to do with the pattern _+_+_+_ or _+_ for that matter.
Could anyone elucidate this for me?

```

• Prev by Date: Re: TIFF file specification
• Next by Date: Re: printing problem with very simple application
• Previous by thread: Re: problem writing debugging utility function
• Next by thread: Re: problem writing debugging utility function