MathGroup Archive 2011

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

Search the Archive

writing own package: cannot read it in..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117922] writing own package: cannot read it in..
  • From: Stuart Little <grobber at gmail.com>
  • Date: Mon, 4 Apr 2011 06:31:36 -0400 (EDT)

Hi,

I've used Mathematica before, but I'm quite new to writing packages. Here's what I'm trying to do: 

I found the example

BeginPackage["foo`"]
Unprotect @@ Names["foo`*"]; 
ClearAll @@ Names["foo`*"]; 
f::usage = "f[x]"
Begin["`Private`"]
f[x_] := Module[{}, x^2]; 
End[]
Protect @@ Names["foo`*"]; 
EndPackage[]

in an online help file. I typed that thing in a new notebook, changed the cell to "Initialization cell", and also changed the style to "code", saved it in a subdirectory somewhere in my Mathematica directory (this is Mathematica 8, by the way), and used the command

Get["D:\\Matedoc\\Progs\\Mathematica 8\\AddOns\\Packages\\foo\\foo.m"]

The problem is that I get the output


Notebook[{Cell[
   BoxData[{RowBox[{"BeginPackage", "[", "\"foo`\"", "]"}], "
     ", RowBox[{RowBox[{RowBox[{"Unprotect", " ", "@@", " ", 
           RowBox[{"Names", "[", "\"foo`*\"", "]"}]}], ";"}], " "}], "
     ", RowBox[{RowBox[{RowBox[{"ClearAll", " ", "@@", " ", 
           RowBox[{"Names", "[", "\"foo`*\"", "]"}]}], ";"}], " "}], "
     ", RowBox[{RowBox[{"f", "::", "usage"}], " ", "=", " ", 
       "\"f[x]\""}], "
     ", RowBox[{"Begin", "[", "\"`Private`\"", "]"}], "
     ", RowBox[{RowBox[{RowBox[{RowBox[{"f", "[", "x_", "]"}], " ", 
           ":=", " ", 
           RowBox[{"Module", "[", 
             RowBox[{RowBox[{"{", "}"}], ",", " ", 
               RowBox[{"x", "^", "2"}]}], "]"}]}], ";"}], " "}], "
     ", RowBox[{"End", "[", "]"}], "
     ", RowBox[{RowBox[{RowBox[{"Protect", " ", "@@", " ", 
           RowBox[{"Names", "[", "\"foo`*\"", "]"}]}], ";"}], " "}], "
     ", RowBox[{"EndPackage", "[", "]"}]}], "Code", 
   InitializationGroup -> True, 
   CellChangeTimes -> {{3.51077*10^9, 3.51077*10^9}, 3.51078*10^9, 
     3.51078*10^9}]}, WindowSize -> {715, 559}, 
 WindowMargins -> {{24, Automatic}, {Automatic, 30}}, 
 FrontEndVersion -> 
  "8.0 for Microsoft Windows (32-bit) (November 7, 2010)", 
 StyleDefinitions -> "Default.nb"]

and the function f[x]=x^2 that the package is trying to define does not become available: when evaluating f[2], I simply get back f[2]. 

I tried long and hard, but I couldn't find a reference to precisely this problem; at this stage, it's becoming very frustrating. I have no idea what all those RowBox things are about..


Thank you,

chirvasitua


  • Prev by Date: Re: SumConvergence mistake?
  • Next by Date: Re: package trouble
  • Previous by thread: Re: ProgressIndicator and ParallelTable problem :(
  • Next by thread: Re: writing own package: cannot read it in..