MathGroup Archive 2004

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

Search the Archive

A module to write a module


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.


  • Prev by Date: Re: Problem with transformation rules in Plot
  • Next by Date: Re: ext kalman filter
  • Previous by thread: Re: subtract a list of interpolating functions from another
  • Next by thread: Re: A module to write a module