# What's the goal of the Macros package?

I see in the Mathematica install a Macros package. In windows the paths is for example:

C:\Program Files\Wolfram Research\Mathematica\10.1\SystemFiles\Components\Macros

I read sometimes that Mathematica lacks proper Macro support like in lisp but is this an attempt to do similar things like in lisp ? Could there be any practical use from this package in the daily lives of mere mortal MM programmers ?

I am not really familiar with LISP macros but from what little I think I know these do not appear to be strongly related. Rather they appear to be utility functions for function authors; it seems that a number of recently added internal top-level definitions use them. Some of them clearly do use meta-programming type expansions so perhaps they are closer to what you want than I think.

I have been meaning for some while to look through these and see if I could figure out what they do and which of them are generally useful. I guess this is as good a time as any to start.

For future reference here are the public package symbols in 10.1:

names = Names["Macros*"]

Output:

{"MacrosAbortFailure", "MacrosBlockSetOptionValues", "MacrosCatchFailure",
"MacrosCheckFailure", "MacrosConditionalRHS", "MacrosDeclareMacro",
"MacrosFailOnMessages", "MacrosHoldSequence", "MacrosIgnoreFailure",
"MacrosInactivateFull", "MacrosInactiveSymbol", "MacrosMessageNames",
"MacrosOptionValuePatterns", "MacrosOptionValues", "MacrosPanic",
"MacrosParseInactives", "MacrosReleaseHoldSequence", "MacrosSetArgumentCount",
"MacrosSetUsage", "MacrosThrowFailure", "MacrosToFailure", "MacrosUnevaluatedLHS",
"MacrosVerify", "MacrosVerifyFalse", "MacrosVerifyTrue", "Macros$FailRHS", "Macros$FailureScope", "Macros$FailureScopeStack", "Macros$MacroHead"}

One of these has a usage message:

?MacrosSetUsage

SetUsage[f , "usage "] attaches a usage message to f in which the special symbols \\$ and \$$can be used as they are in DocuTools. SetUsage[f , "Subscript[usage, 1] ", "Subscript[usage, 2] ", …] concatenates several usage messages to f , each of which will show as one line when displayed with ?. Since I am not a DocuTools user this is rather enigmatic to me but a peek at the definition of SetUsage shows that its core function is: GeneralUtilitiesPrintDefinitions @ MacrosMacrosPackagePrivatetolinearsyntax MacrosMacrosPackagePrivatetolinearsyntax[string_] := StringReplace[ string, {"->" -> "\[Rule]", "'" -> "\"", w : (LetterCharacter ..) ~~ "" ~~ i : DigitCharacter | LetterCharacter :> ToString[Style[Subscript[w, Style[i, "TR"]], "TI"], StandardForm] <> "\[VeryThinSpace]", w : (LetterCharacter ..) ~~ "(" ~~ Shortest[i___] ~~ ")" :> ToString[Style[Subscript[w, Style[i, "TR"]], "TI"], StandardForm] <> "\[VeryThinSpace]", w : (LetterCharacter ..) ~~ "" :> ToString[Style[w, "TI"], StandardForm] <> "\[VeryThinSpace]", "$$" -> ToString[Style["…", "TR"]]}];

So it seems that $$simply becomes an ellipsis while  is used for quick subscripts: Macros`SetUsage[foo, "foo[bar1, baz1] does bar1 to baz1 and$$"];

?foo

As I dig through this package in the coming days I shall add descriptions of my understanding of them, assuming someone has not done this before me.

• +1. I would add to this that Lisp-style macros are not possible without introducing a separate "read-time", that is, a stage where code has been read (or is being read), but not yet executed, and where one could attach some hooks. In fact, my project on fine-grained modules was meant to provide such read-time (among other things), and I was particularly having in mind Lisp-style macro support. Hopefully, I will move that along some time soon. May 19 '15 at 15:59
• @Leonid Thanks. I thought there was a distinction something like that. May 19 '15 at 18:57
• Formatted usage messages, set with SetUsage, will be displayed incorrectly in the autocompletion popup :-( Oct 6 '15 at 10:46
• @Szabolcs So it seems. :-/ I see that I never extended this answer as I intended too. (I write that far too often I fear.) As I suppose you've noticed I am taking a break from Mathematica (software and site) as I was feeling burned out and I don't want my participation to become a drudgery. I can't remember the present knowledge of the auto-completion popup behavior; don't some System symbols have formatting problems there too? Oct 7 '15 at 16:46