Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1460

writing own package: cannot read it in..

From Stuart Little <grobber@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject writing own package: cannot read it in..
Date 2011-04-04 10:31 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <inc6m2$vl$1@smc.vnet.net> (permalink)

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | NextNext in thread | Find similar | Unroll thread


Thread

writing own package: cannot read it in.. Stuart Little <grobber@gmail.com> - 2011-04-04 10:31 +0000
  Re: writing own package: cannot read it in.. "Nasser M. Abbasi" <nma@12000.org> - 2011-04-05 10:42 +0000

csiph-web