MathGroup Archive 2006

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

Search the Archive

Using Get in a Module

  • To: mathgroup at
  • Subject: [mg64207] Using Get in a Module
  • From: "Stu Schaffner" <arglebargle at>
  • Date: Mon, 6 Feb 2006 02:49:06 -0500 (EST)
  • Sender: owner-wri-mathgroup at

I am returning to Mathematica 5.2 after a hiatus, and have a few questions. 
I have text files that contain valid Mathematica assignments, such as
   x = {1,2,3};
There are several assignments in a single file, as the files are data dumps 
from a larger system.  If a top-level notebook contains
everything is fine.  However,
   fn = path<>"filename"<>".txt";
does not work.  It can be fixed by putting parentheses around the fn 
variable:  <<(fn).  I presume this forces evaluation of fn, so << sees a 
String instead of a Symbol whose downvalue is a String.  I can live with 
this, but wonder why it is necessary.

Next, I made a function and added it to a package.  The function now 
contained the << operator:
   fun::usage = ...

The package notebook compiled with no errors, but when I did a Needs on the 
resulting .m file, I got a syntax error on the <<.  (I notice that the error 
message still gives false line numbers.)  I made this go away by replacing 
<< with Get.  This looks like a bug but, again, I can live with it.  However 
the module does not seem to be able to access the symbols defined by the 
assignment statements.  After the Get is processed, the new symbols appear 
in Global context of the top-level notebook, but are not visible to the 
package function that contained the Get.  I played a bit with defining local 
symbols with the same name and by using Global`x in the package function, 
but none of this helped.  It appears that Mathematica has preprocessed the 
module enough that it can't cope with dynamic changes to the namespace.  Is 
this a feature or a bug?  Is there a workaround?

Stu Schaffner
my real address is my nickname followed by the first three letters of my 
last name (all one word) at 

  • Prev by Date: Re: NIntegrate[Abs] bug in v5.1, not v5.0
  • Next by Date: Re: determinant of sparse matrix
  • Previous by thread: Re: Problem plotting high-order Laguerre polynomials
  • Next by thread: Re: Using Get in a Module