7
$\begingroup$

Code

FullForm[Hold[?name]]

Syntax::bktmcp: Expression "Hold[?name]]" has no closing "]".

Syntax::sntxi: Incomplete expression; more input is needed .

Question

This is exercise 3.2 (page 47) of Power Programming w/ Mathematica

The task is:

"determine the internal representation of the expressions ?name and ??name"

The above is what I tried. It failed. How do I win?

$\endgroup$
  • 2
    $\begingroup$ @term-rewritica - you have Wagner's book? You lucky thing - mine was borrowed by someone years ago and never seen again. $\endgroup$ – Verbeia Jul 10 '12 at 7:28
  • $\begingroup$ @Verbeia: It's a most intense reading. Reminds me of the first time I read SICP. $\endgroup$ – user1602 Jul 10 '12 at 8:21
  • $\begingroup$ @Verbeia I do have a copy of that one too (ironically, bought from Amazon fo $40 in 2004, when I just started learning Mathematica as a programming language - and I had no idea about the usefulness of the book at the time, it was a blind purchase). I was lucky to not give it to anyone (well, no one asked). $\endgroup$ – Leonid Shifrin Jul 10 '12 at 10:16
  • 1
    $\begingroup$ @term-rewritica Actually, Roman Maeder's books are more intense reading to me. I think, Wagner wrote his book on just the right level, for someone who knows some Mathematica and wants to bring their M skills to the next level. Can be a little hard to read for a complete beginner, but at least you don't have to read between the lines ( which is what happens all the time with Maeder's books - which is why they are great for experienced users). Wagner's book is still my favorite book on M programming. $\endgroup$ – Leonid Shifrin Jul 10 '12 at 10:22
  • 1
    $\begingroup$ @term-rewritica Yes, best books for it you have to hunt for. Part of the fun :) $\endgroup$ – Leonid Shifrin Jul 10 '12 at 20:59
18
$\begingroup$

To programmatically find the internal representation of the shortforms, you can use MakeExpression, which gives the result wrapped in HoldComplete. Here's an example:

MakeExpression@"?name"
(* HoldComplete[Information["name", LongForm -> False]] *)

MakeExpression@"??name"
(* HoldComplete[Information["name", LongForm -> True]] *)
$\endgroup$
6
$\begingroup$

Here are a couple of alternatives to R.M's method for seeing what Mathematica makes of input.

The input forms of every line entered are stored in the DownValues of In.
Starting with a new session or after using Quit[], evaluating each in a separate Cell:

?Mod

??Plus

DownValues[In]
{HoldPattern[In[1]] :> Information["Mod", LongForm -> False], 
 HoldPattern[In[2]] :> Information["Plus", LongForm -> True], 
 HoldPattern[In[3]] :> DownValues[In]}

Alternatively you could set a $Pre function to echo input:

$Pre = Function[, Print@Unevaluated@#; #, HoldAll];

?Plus
Information["Plus", LongForm -> False]

x+y+z represents a sum of terms.  >>

$\endgroup$

Your Answer

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