MathGroup Archive 2008

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

Search the Archive

Assigning multiple variables within a Block[] statement (e.g. {a,b} = {c,d})

  • To: mathgroup at
  • Subject: [mg88283] Assigning multiple variables within a Block[] statement (e.g. {a,b} = {c,d})
  • From: "" <dnquark at>
  • Date: Wed, 30 Apr 2008 07:02:27 -0400 (EDT)
  • Organization: Purdue University

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};

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.

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?



  • Prev by Date: Re: Complex Plot
  • Next by Date: Re: locator snap
  • Previous by thread: Re: ChebyshevT command syntax and polynomial question using mathematica