Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Assigning multiple variables within a Block[] statement (e.g.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88309] Re: Assigning multiple variables within a Block[] statement (e.g.
  • From: Januk <ggroup at sarj.ca>
  • Date: Thu, 1 May 2008 03:21:40 -0400 (EDT)
  • References: <fv9jsm$50f$1@smc.vnet.net>

Hi Leo,

For question 2, you could use a line like:

Set[Evaluate[paramlistnames], paramlistnames /. paramlist]

Good luck!

On Apr 30, 7:07 am, "news.purdue.edu" <dnqu... at yahoo.com> wrote:
> What I'm trying to do:
> I have a list of parameters that I am using across several functions.  I am
> trying to come up with a good way to avoid copying/pasting these parameter
> assignments everywhere.  Here is an example code that sort of accomplishes
> this goal: (Suppose my parameters are a,b, and c)
>
> paramlist = {a -> 1, b -> 4, c -> 8};
> paramlistnames = First /@ paramlist;
>
> foobar2[x_] := Block[Evaluate[Flatten[{paramlistnames, {d, e, f}}]],
> {a, b, c} = paramlistnames /. paramlist;
> {d,e,f} = {1,1,1};
> x*a*b*c*d*e*f
> ]
>
> The line
> {a, b, c} = paramlistnames /. paramlist;
> effectively sets a, b, and c to their values, at which point I can proceed
> with the rest of the function.
>
> Questions:
> 1. Is this the most effective way to accomplish the task at hand?  If no,
> what is?
>
> 2. Note that I still have to explicitly use {a, b, c} = paramlistnames /.
> paramlist; something like Hold[paramlistnames] =  paramlistnames /.
> paramlist; results in an error message.  Is there a way to do the assignment
> but use the "paramlistnames" somehow so that I don't have to name the
> variables explicitly?
>
> Thanks,
>
> --Leo



  • Prev by Date: Re: Assigning multiple variables within a Block[] statement (e.g. {a,b} = {c,d})
  • Next by Date: Re: Complex Plot
  • Previous by thread: Re: Assigning multiple variables within a Block[] statement (e.g. {a,b} = {c,d})
  • Next by thread: Re: Assigning multiple variables within a Block[] statement (e.g.