MathGroup Archive 1999

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

Search the Archive

Re: List of local Variables in Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16200] Re: List of local Variables in Module
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 5 Mar 1999 00:40:38 -0500
  • References: <7bg1oh$5lm@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Peter Breitfeld wrote in message <7bg1oh$5lm at smc.vnet.net>...
>
>I want to implement a function like this:
>
>myFunction[f_,x_,n_Integer]:=
>  Module[Join[Array[a,n+1,0],{z,expr}],
>  <<<< some code to construct a polynomial in x of degree n with
>      coefficients a[0]...a[n] >>>>>
>]
>
>Now Mathematica complains Join[...] is not a list.
>But if I type
>
>In= Join[Array[a,2,0],{z,expr}]//FullForm
>Out=List[a[0],a[1],z,expr]
>
>It _is_ a List.
>
>Changing n+1 to a number e.g 20 doesn't change Mathematicas behavior.
>
>All what helped, was
> Module{u=Array[a,n+1,0],z,expr}, .....
>
>but now the a[i] are global.
>
>Is there a way to get what I want?
>
>
>--
>
>es gruesst
>      Peter
>--
>=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=
>  Peter Breitfeld, Saulgau, Germany       (PGP public key: 08548045)
>

Peter:

Module first checks that its first entry is a list; but here, since has the
attribute HoldAll, it sees only the unevaluated
Join[Array[a,n+1,0],{z,expr}]], which is not a list.
This suggests that we force the evaluation - but this too does not work

myFunction[f_,x_,n_Integer]:=
Module[Evaluate[Join[Array[a,n+1,0],{z,expr}]],
]

myFunction[f,x,4]
Module::"lvsym":
    "Local variable specification \!\({\(a[0]\), \(a[1]\), \(a[2]\), \
\(a[3]\), \(a[4]\), z, expr}\) contains \!\(a[0]\) which is not a symbol or
\
an assignment to a symbol."

Out[10]=
Module[{a[0],a[1],a[2],a[3],a[4],z,expr},Null]

We could make a list of symbols a0,a1,...an


myFunction2[f_,x_,n_Integer]:=
Module[Evaluate[
   Join[Table[ToExpression[ "a"<>ToString[i]],{i,0,n}],{z,expr}]],
]

Which is UK because of
Join[Table[ToExpression[ "a"<>ToString[i]],{i,0,4}],{z,expr}]

    {a0,a1,a2,a3,a4,z,expr}

But maybe the following version ot your second form will be OK

myFunction3[f_,x_,n_Integer]:=
Module[{u, a,z,expr},
u =Array[a,n+1,0]
]

myFunction3[f,x,4]

{a$3[0],a$3[1],a$3[2],a$3[3],a$3[4]}


Allan Hayes

---------------------
Allan Hayes
Mathematica Training and Consulting
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565





  • Prev by Date: Re: How to draw the level curves ?
  • Next by Date: DSolve Problem
  • Previous by thread: Re: List of local Variables in Module
  • Next by thread: Re: List of local Variables in Module