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


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

writing own package: cannot read it in..

Started byStuart Little <grobber@gmail.com>
First post2011-04-04 10:31 +0000
Last post2011-04-05 10:42 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  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

#1460 — writing own package: cannot read it in..

FromStuart Little <grobber@gmail.com>
Date2011-04-04 10:31 +0000
Subjectwriting own package: cannot read it in..
Message-ID<inc6m2$vl$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#1478

From"Nasser M. Abbasi" <nma@12000.org>
Date2011-04-05 10:42 +0000
Message-ID<inern4$j69$1@smc.vnet.net>
In reply to#1460
On 4/4/2011 3:31 AM, Stuart Little wrote:
> 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


You must be referring to this page:

http://12000.org/my_notes/how_to_write_package_in_mathematica/index.htm

But I do NOT see anywhere in the above document where it says to do what
you did on your own initiative, which is

                         "and also changed the style to "code",

Why did you do that for?

How about trying the same steps again, but do not change the style to code? and
see if that works.

When I tried the the steps myself, it worked, but I did not have to change
style to code. There was no reason to.

--Nasser

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web