Skip to main content
added Skeleton.m
Source Link

You'll want to at least look at chapters 1-2 of Roman Maeder's Programming in Mathematica for starters. That was the walkthrough I used when I was starting out with package writing. I'll update this answer if I can remember the other references I used.

In particular: pages 47 to 48 of, the third edition providebook provides the listing of a template package file, named Skeleton.m that. Here is a template that you can use;what it looks like:

(* :Title: Skeleton.m -- a package template *) (* :Context: ProgrammingInMathematica`Skeleton` *) (* :Author: Roman E. Maeder *) (* :Summary: The skeleton package is a syntactically correct framework for package development. *) (* :Copyright: © <year> by <name or institution> *) (* :Package Version: 2.0 *) (* :Mathematica Version: 3.0 *) (* :History: 2.0 for Programming in Mathematica, 3rd ed. 1.1 for Programming in Mathematica, 2nd ed. 1.0 for Programming in Mathematica, 1st ed. *) (* :Keywords: template, skeleton, package *) (* :Sources: Roman E. Maeder. Programming in Mathematica, 3rd ed. Addison-Wesley, 1996. *) (* :Warnings: <description of global effects, incompatibilities> *) (* :Limitations: <special cases not handled, known problems> *) (* :Discussion: <description of algorithm, information for experts> *) (* :Requirements: ProgrammingInMathematica/Package1.m ProgrammingInMathematica/Package2.m ProgrammingInMathematica/Package3.m *) (* :Examples: <sample input that demonstrates the features of this package> *) (* set up the package context, including public imports *) BeginPackage["ProgrammingInMathematica`Skeleton`", "ProgrammingInMathematica`Package1`", "ProgrammingInMathematica`Package2`"] (* usage messages for the exported functions and the context itself *) Skeleton::usage = "Skeleton.m is a package that does nothing." Function1::usage = "Function1[n] does nothing." Function2::usage = "Function2[n, (m : 17)] does even more nothing." (* error messages for the exported objects *) Skeleton::badarg = "You twit, you called `1` with argument `2`!" Begin["`Private`"] (* begin the private context (implementation part) *) Needs["ProgrammingInMathematica`Package3`"] (* read in any hidden imports *) (* unprotect any system functions for which definitions will be made *) protected = Unprotect[ Sin, Cos ] (* definition of auxiliary functions and local (static) variables *) Aux[f_] := Do[something] staticvar = 0 (* definition of the exported functions *) Function1[n_] := n Function2[n_, m_ : 17] := n m /; n < 5 || Message[Skeleton::badarg, Function2, n] (* definitions for system functions *) Sin /: Sin[x_]^2 := 1 - Cos[x]^2 Protect[ Evaluate[protected] ] (* restore protection of system symbols *) End[ ] (* end the private context *) Protect[ Function1, Function2 ] (* protect exported symbols *) EndPackage[ ] (* end the package context *) 

For your own package, just modify, replace and/or delete stuff from the template as needed.

You'll want to at least look at chapters 1-2 of Roman Maeder's Programming in Mathematica for starters. That was the walkthrough I used when I was starting out with package writing. I'll update this answer if I can remember the other references I used.

In particular: pages 47 to 48 of the third edition provide the listing of a file, Skeleton.m that is a template that you can use; just replace and/or delete stuff as needed.

You'll want to at least look at chapters 1-2 of Roman Maeder's Programming in Mathematica for starters. That was the walkthrough I used when I was starting out with package writing.

In particular, the book provides the listing of a template package file, named Skeleton.m. Here is what it looks like:

(* :Title: Skeleton.m -- a package template *) (* :Context: ProgrammingInMathematica`Skeleton` *) (* :Author: Roman E. Maeder *) (* :Summary: The skeleton package is a syntactically correct framework for package development. *) (* :Copyright: © <year> by <name or institution> *) (* :Package Version: 2.0 *) (* :Mathematica Version: 3.0 *) (* :History: 2.0 for Programming in Mathematica, 3rd ed. 1.1 for Programming in Mathematica, 2nd ed. 1.0 for Programming in Mathematica, 1st ed. *) (* :Keywords: template, skeleton, package *) (* :Sources: Roman E. Maeder. Programming in Mathematica, 3rd ed. Addison-Wesley, 1996. *) (* :Warnings: <description of global effects, incompatibilities> *) (* :Limitations: <special cases not handled, known problems> *) (* :Discussion: <description of algorithm, information for experts> *) (* :Requirements: ProgrammingInMathematica/Package1.m ProgrammingInMathematica/Package2.m ProgrammingInMathematica/Package3.m *) (* :Examples: <sample input that demonstrates the features of this package> *) (* set up the package context, including public imports *) BeginPackage["ProgrammingInMathematica`Skeleton`", "ProgrammingInMathematica`Package1`", "ProgrammingInMathematica`Package2`"] (* usage messages for the exported functions and the context itself *) Skeleton::usage = "Skeleton.m is a package that does nothing." Function1::usage = "Function1[n] does nothing." Function2::usage = "Function2[n, (m : 17)] does even more nothing." (* error messages for the exported objects *) Skeleton::badarg = "You twit, you called `1` with argument `2`!" Begin["`Private`"] (* begin the private context (implementation part) *) Needs["ProgrammingInMathematica`Package3`"] (* read in any hidden imports *) (* unprotect any system functions for which definitions will be made *) protected = Unprotect[ Sin, Cos ] (* definition of auxiliary functions and local (static) variables *) Aux[f_] := Do[something] staticvar = 0 (* definition of the exported functions *) Function1[n_] := n Function2[n_, m_ : 17] := n m /; n < 5 || Message[Skeleton::badarg, Function2, n] (* definitions for system functions *) Sin /: Sin[x_]^2 := 1 - Cos[x]^2 Protect[ Evaluate[protected] ] (* restore protection of system symbols *) End[ ] (* end the private context *) Protect[ Function1, Function2 ] (* protect exported symbols *) EndPackage[ ] (* end the package context *) 

For your own package, just modify, replace and/or delete stuff from the template as needed.

Post Merged (destination) from mathematica.stackexchange.com/questions/303/…
added 179 characters in body
Source Link

You'll want to at least look at chapters 1-2 of Roman Maeder's Programming in Mathematica for starters. That was the walkthrough I used when I was starting out with package writing. I'll update this answer if I can remember the other references I used.

In particular: pages 47 to 48 of the third edition provide the listing of a file, Skeleton.m that is a template that you can use; just replace and/or delete stuff as needed.

You'll want to at least look at chapters 1-2 of Roman Maeder's Programming in Mathematica for starters. That was the walkthrough I used when I was starting out with package writing. I'll update this answer if I can remember the other references I used.

You'll want to at least look at chapters 1-2 of Roman Maeder's Programming in Mathematica for starters. That was the walkthrough I used when I was starting out with package writing. I'll update this answer if I can remember the other references I used.

In particular: pages 47 to 48 of the third edition provide the listing of a file, Skeleton.m that is a template that you can use; just replace and/or delete stuff as needed.

Source Link

You'll want to at least look at chapters 1-2 of Roman Maeder's Programming in Mathematica for starters. That was the walkthrough I used when I was starting out with package writing. I'll update this answer if I can remember the other references I used.