[Date Index]
[Thread Index]
[Author Index]
Re: Usage Messages in Mathematica
*To*: mathgroup at smc.vnet.net
*Subject*: [mg131311] Re: Usage Messages in Mathematica
*From*: Simon <simon.rochester at gmail.com>
*Date*: Thu, 27 Jun 2013 06:31:14 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Delivered-to*: l-mathgroup@wolfram.com
*Delivered-to*: mathgroup-outx@smc.vnet.net
*Delivered-to*: mathgroup-newsendx@smc.vnet.net
*References*: <20121227100447.E595B6866@smc.vnet.net> <20121228103623.75A716873@smc.vnet.net>
I think I've got a solution to this problem (I've also posted this over on Stack Exchange Mathematica):
During evaluation, Information[symbol] and ?symbol both call a function System`Dump`fixmessagestring, with definition
System`Dump`fixmessagestring[System`Dump`s_] :=
"\""<>StringReplace[System`Dump`s,{"\n"->"\\n","\\"->"\\\\","\""->"\\\""}]<>"\""
If one redefines this function, by evaluating
System`Dump`fixmessagestring[System`Dump`s_] := ToString@InputForm@System`Dump`s
it appears to accomplish the same task, but without screwing up user-defined usage messages. I've checked this in Mathematica versions 6, 7, and 8, but not version 9.
So far I haven't seen any negative side effects as a result of this redefinition. I would be very interested if anybody finds a reason not to make this change.
-Simon Rochester
On Saturday, December 29, 2012 7:24:51 PM UTC-8, Murray Eisenberg wrote:
> Same thing on my Mac OS X installation of Mathematica 9. (Quotes the
>
> first time in output from ?f, not thereafter.)
>
>
>
> On the other hand, of course, simply evaluating f::usage produces output
>
> with no quotes.
>
>
>
> On Dec 29, 2012, at 3:13 PM, djmpark <djmpark at comcast.net> wrote:
>
>
>
> > No, on my system (M9, Windows 7) the first time
>
> >
>
> > ?f
>
> >
>
> > is evaluated I obtain a usage message with quotes around it. If the same
>
> > statement is evaluated again the quotes go away. Of course, it is the first
>
> > evaluation that the user will see.
>
> >
>
> >
>
> > David Park
>
> > djmpark at comcast.net
>
> > http://home.comcast.net/~djmpark/index.html
>
> >
>
> >
>
> >
>
> > From: Bob Hanlon [mailto:hanlonr357 at gmail.com]
>
> >
>
> >
>
> > Using both Format and usage messages seems to work.
>
> >
>
> > Clear[f];
>
> > Format[f[n_, x_]]:=
>
> > Subscript[f, n][x];
>
> > f::usage="f[n, x] gives " <>
>
> > ToString[f[n, x], StandardForm]<>".";
>
> >
>
> > f::usage
>
> >
>
> > f[n, x]
>
> >
>
> > f[n, x]//TraditionalForm
>
> >
>
> > Clear[g];
>
> > Format[g[n_, a_, x_]]:=
>
> > Power[Subscript[g, n], a][x];
>
> > g::usage="g[n, a, x] gives " <>
>
> > ToString[g[n, a, x], StandardForm]<>".";
>
> >
>
> > g::usage
>
> >
>
> > g[n, a, x]
>
> >
>
> > g[n, a, x]//TraditionalForm
>
> >
>
> >
>
> > Bob Hanlon
>
> >
>
> >
>
> > On Fri, Dec 28, 2012 at 5:36 AM, Murray Eisenberg =
>
> <murray at math.umass.edu>
>
> > wrote:
>
> >> And yet usage messages for built-in objects seem to handle in-line
>
> >> expressions and subscripts with aplomb. See, for example:
>
> >>
>
> >> Subscript::usage
>
> >>
>
> >>
>
> >> On Dec 27, 2012, at 5:04 AM, djmpark <djmpark at comcast.net> wrote:
>
> >>
>
> >>> An extremely weak features of Mathematica is the design of Usage
>
> >>> messages, which seems to be stuck at Version 1, although the
>
> >>> technology has moved far beyond that.
>
> >>>
>
> >>> The present design is not up to the task and full of gotchas. For
>
> >>> example, how does one include a box structure, for example a
>
> >>> subscripted symbol, within a usage message? If one just enters a
>
> >>> subscript then the first time the message is displayed there are
>
> >>> quotes around it and the second time the quotes go away. If one
>
> >>> starts an InlineCell within the string and enters the expression then
>
> >>> that problem goes away. If one then moves the usage definition to a
>
> >>> package and Runs the package it works OK. But if one saves and closes
>
> >>> the package, quits the kernel and then reinitializes, loading the
>
> >>> package, the usage message is defective giving the InputForm of the
>
> >>> box expression. Mathematica parses and changes the usage messages when
>
> > the file is read.
>
> >>>
>
> >>> The String form is just not adequate for usage messages. Nor is it
>
> >>> adequate to contain information on overloading functions. Usage
>
> >>> definitions should be expressions. Something like the following:
>
> >>>
>
> >>> Usage[FunctionName] = {{template, usageExpression}..}
>
> >>>
>
> >>> (The usageExpression might be a Row containing Strings and
>
> >>> mathematical expressions.)...
>
> >>
>
> >> ---
>
> >> Murray Eisenberg murray at math.umass.edu
>
> >> Mathematics & Statistics Dept.
>
> >> Lederle Graduate Research Tower phone 413 549-1020 (H)
>
> >> University of Massachusetts 413 545-2838 (W)
>
> >> 710 North Pleasant Street fax 413 545-1801
>
> >> Amherst, MA 01003-9305
>
> >>
>
> >>
>
> >>
>
> >>
>
> >>
>
> >>
>
> >
>
>
>
> ---
>
> Murray Eisenberg murray at math.umass.edu
>
> Mathematics & Statistics Dept.
>
> Lederle Graduate Research Tower phone 413 549-1020 (H)
>
> University of Massachusetts 413 545-2838 (W)
>
> 710 North Pleasant Street fax 413 545-1801
>
> Amherst, MA 01003-9305
Prev by Date:
**Re: What is f[1]? Advanced question**
Next by Date:
**What is f[1]? Advanced question**
Previous by thread:
**Re: What is f[1]? Advanced question**
Next by thread:
**Re: Removing Outliers from List**
| |