MathGroup Archive 2010

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

Search the Archive

Can't read a package

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114184] Can't read a package
  • From: James Stein <james at stein.org>
  • Date: Fri, 26 Nov 2010 05:29:33 -0500 (EST)

I am very frustrated that, after a year with Mathematica, I still cannot
create and use packages. I must be missing something elementary.

Here is what I have attempted.  I think there is just one missing part:

Step 1: "write" a package:
In the tutorial "Setting Up Mathematica Packages" there is source for the
sample package "Collatz.m". I copied that source and pasted it into a new
Mathematica file, then used the "Save As" command to save the file as a
package, naming it "collatz.m" and placing it in a folder called packages.

Step 2: Try to use the package:
1. I create a new Mathematica notebook file, put the following five lines in
it, and save it as "collatz.nb" alongside "collatz.m":

SetDirectory["~/desktop/MathNoteBooks/packages"];
FileNames[]
PrependTo[$Path, Directory[]]
(* missing step; neither << collatz.m nor Import["collatz.m"] works *)
Collatz[5] (* 'Collatz' remains undefined *)


Missing Step:
Executing the above code, the output from "FileNames" shows that both files
exist in the directory.  So what code should replace the fourth line above?
Or have I gone astray elsewhere?


  • Prev by Date: Re: understanding code
  • Next by Date: Re: Why this can't be reduced by mathematica?!
  • Previous by thread: Re: Compile and arrays
  • Next by thread: Re: Can't read a package