A module to write a module
- To: mathgroup at smc.vnet.net
- Subject: [mg48543] A module to write a module
- From: Goyder Dr HGD <h.g.d.goyder at cranfield.ac.uk>
- Date: Fri, 4 Jun 2004 04:50:59 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In an attempt to save a few seconds of typing I am trying to generate a
module that will provide a template for a new module. Thus by typing the
input
ModuleTemplate[myName]
I will generate the following
ClearAll[myName];
myName::usage = "myName...";
myName[] := Module[{},
Print["myName, at stage 1:"];
Print["myName, at stage 2:"];
Print["myName, at stage 3:"];
]
The above should be in an Input cell ready to be edited into the module I
need. It even has Print statements ready to tell me what it has managed to
do before inevitably going wrong. Having saved a few seconds in typing I
might actually fill in the usage message. The above could even be
implemented by a button so that I don't even have to type ModuleTemplate.
All I have managed so far is the following module.
ClearAll[ModuleTemplate];
ModuleTemplate::usage = "ModuleTemplate[yourName]
- a fast way of getting started.";
ModuleTemplate[a_] := Module[{},
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. I feel that some subtle use of MakeBoxes is
needed. How do I fix this? Should I add any other features into my module
template?
Many thanks for any help.
Hugh Goyder
--
This message has been scanned for viruses and
dangerous content by the Cranfield MailScanner, and is
believed to be clean.