MathGroup Archive 2007

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

Search the Archive

Re: Module in a package

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72970] Re: Module in a package
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 27 Jan 2007 05:29:34 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <epcnf4$849$1@smc.vnet.net>

Miguel wrote:
> When I use Module in a package Mathematica yields an error message and
> I d'ont understand the reason.
>  This is an example
> 
> Package Calor`Combustion`
> 
> CO2[c_,h_,o_]:=(
-----------------^
Extra parentheses: must be discarded

> Module[{nci=(c*10/12),nhi=(h*10/2),noi=(o*10/32),a,b,c,d,e},
-------------------------------------------------------^
c should not be redefined here
a, b, d, e are not use in the function: no need to define them as local 
variables

> nc=nci;
> nh=nhi-(2*noi);
> no=nc+(nh/2);
--^^
However, nc, nh, and no are *global* variables (they are not local to 
the module): are you sure this is what you want?

> 2*no+5*nh
> ]

<snip>

Hi Miguel,

Even outside a package your code is not working. Try the following:

In[1]:=
CO2[c_, h_, o_] :=
Module[{nci, nhi, noi, nc, nh, no},
	nci = c*(10/12);
	nhi = h*(10/2);
	noi = o*(10/32);
	nc = nci;
	nh = nhi - 2*noi;
	no = nc + nh/2;
	2*no + 5*nh
]

In[2]:=
CO2[60, 35, 5]

Out[2]=
4525
----
  4

Best regards,
Jean-Marc


  • Prev by Date: Re: Mathematica and ML (Functional Programming Language)
  • Next by Date: NDSolve -- initial conditions
  • Previous by thread: Module in a package
  • Next by thread: Re: [TS 1774]--Re:Wolfram Workbench: SVN & notebook diffs