
(*********************************************************************

        Adapted from
        Roman E. Maeder: Programming in Mathematica,
        Second Edition, Addison-Wesley, 1991.

 *********************************************************************)


(* set up the package context, included any imports *)

BeginPackage["Skeleton`", "Package1`", "Package2`"]

Needs["Package3`"]    (* read in any hidden imports *)


(* 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."


Begin["`Private`"]    (* begin the private context *)


(* unprotect any system functions for which rules will be defined *)

protected = Unprotect[ Sin, Cos ]


(* definition of auxiliary functions and local (static) variables *)

Aux[f_] := Do[something]

staticvar = 0


(* error messages for the exported objects *)

Skeleton::badarg = "You twit, you called `1` with argument `2`!"


(* definition of the exported functions *)

Function1[n_] := n

Function2[n_, m_:17] := n m /; n < 5 || Message[Skeleton::badarg, Function2, n]


(* rules 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 *)
