MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A module to write a module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48905] Re: A module to write a module
  • From: "Peltio" <peltio at twilight.zone>
  • Date: Wed, 23 Jun 2004 02:50:57 -0400 (EDT)
  • References: <c9pfkj$sr9$1@smc.vnet.net>
  • Reply-to: "Peltio" <peltioNOSP at Mdespammed.com.invalid>
  • Sender: owner-wri-mathgroup at wolfram.com

"Goyder Dr HGD" wrote

>    ClearAll[myName];
>    myName::usage = "myName...";
>    myName[] :=
>        Module[{},
>        Print["myName, at stage 1:"];
>    ]

>All I have managed so far is the following module.
[snip]
>    NotebookWrite[SelectedNotebook[],
>    Cell[BoxData[MakeBoxes[ClearAll[#]; #::usage = "#[]...";
>     #[] := Module[{}, Print["# Stage 1:"];]]], "Input"]] &[a]

>This is beginning to work but I can't get line breaks where I want them,
>the usage message gets wrapped in quotes and the # in quotes does not
>translate into the name in quotes.

My two cents on the last issue: MakeBoxes is very evaluation-proof, so you
might want to pass to it an already (partially) evaluated expression. Using
Hold to prevent the actual evaluation and Replace to change your placeholder
(here called 'ppp' (Peltio's Preffered Placeholder) ) into your name 'a' you
could get something that resembles what you're looking for:

    NotebookWrite[SelectedNotebook[], Cell[
        BoxData[MakeBoxes @@ (Hold[
            ClearAll[ppp];
            ppp::usage = StringJoin[ToString[ppp],"[]..."];
            ppp[] := Module[
                {},
                Print[StringJoin[ToString[ppp], " at Stage 1:"]];
            ]
            ] /. ppp -> a)
        ], "Input"]
    ]

you could pass an evaluated string instead of the StringJoin sequence above,
I guess, but that's just an aesthetic matter (it might require a separated
evaluation and then a replacement of this kind

    /. {ppp -> a,
        ps1->StringJoin[ToString[a],"[]..."],
        ps2->StringJoin[ToString[ppp], " at Stage 1:"]}

Oh well, here it is:

ModuleTemplate[a_]:=
    NotebookWrite[SelectedNotebook[], Cell[
        BoxData[MakeBoxes @@ (Hold[
            ClearAll[ppp];
            ppp::usage = ps1;
            ppp[] := Module[
                {},
                Print[ps2];
            ]
            ]  {ppp -> a,
                ps1->StringJoin[ToString[a],"[]..."],
                ps2->StringJoin[ToString[ppp], " at Stage 1:"]}
            )
        ], "Input"]
    ]
]

As for usage being wrapped in quotes... the mighty manual says it is valid
syntax, so we could live with that.
I *do not even think* to look into into the linebreak issue : ), though.

Hope this helps as a starting point, though.
Peltio
Invalid address in reply-to. Crafty demunging required to mail me.




  • Prev by Date: Re: Sort by buried element in list
  • Next by Date: Re: Mathematica can't do this double integral
  • Previous by thread: Re: A module to write a module
  • Next by thread: Re: ext kalman filter