Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Making new Contexts in Modules in a package

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48376] Re: Making new Contexts in Modules in a package
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 26 May 2004 02:41:28 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <c8vcv5$alu$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

a) you can't have a function with name Function[] because
   Function[] is used by Mathematica for pure functions
b) you should not create contexts for file names because
   file names can have . \ of / characters in it and this is
   not allowed in a context
c) you must build a symbol in the context you wish with
   Evaluate[
     ToExpression[
       stringWithContextName<>"`unmodifyedlist"
      ]
    ]=ReadList[__]

Regards 
  Jens

Johan van der Meer wrote:
> 
> Hello, I am fairly new to mathematica and need some help with this
> context stuff :-).
> 
> What I want is to read with a function in a package some data (from a
> file), and put that in a (nested) list called listname`unmodifiedlist.
> 
> The idea is to make modifications to that list with other functions,
> where the new list name is listname`modifiedlist.
> 
> So what I want is a function called MakeList[data_String], that reads
> the data and puts it in the variable unmodifiedlist in the (newly made)
> context data.
> Then, in my notebook I can simply type:
> MakeList["data"]
> Plot[data`unmodifiedlist]
> 
> to plot it for example.
> 
> I have in a package (package.m) a function that looks like this:
> 
> Function[data_String]:=
> Module[{newcontext="",unmodifiedlist,readlist},
> 
> unmodifiedlist=ReadList[OpenRead[data],Number];
> Close[data];
> 
> newcontext=ToString[context]<>"`";
> $ContextPath=Join[$ContextPath,{newcontext}];
> 
> $Context=newcontext;
> 
> unmodifiedlist=readlist;
> 
> ]
> 
> However, this doesn't seem to work. What I also tried is to change the
> context in the beginning of my module to "data`". I am not sure if this
> is good programming either, or if I should be wanting this with
> mathematica, but any help is greatly appreciated.
> 
> Regards,
> 
> Johan van der Meer


  • Prev by Date: Re: Problem with function
  • Next by Date: Re: WTD: point intersection in space
  • Previous by thread: Making new Contexts in Modules in a package
  • Next by thread: ANFIS