[Date Index]
[Thread Index]
[Author Index]
Re: Assigning multiple variables within a Block[] statement (e.g. {a,b} = {c,d})
*To*: mathgroup at smc.vnet.net
*Subject*: [mg88295] Re: Assigning multiple variables within a Block[] statement (e.g. {a,b} = {c,d})
*From*: "David Park" <djmpark at comcast.net>
*Date*: Thu, 1 May 2008 03:19:07 -0400 (EDT)
*References*: <fv9jsm$50f$1@smc.vnet.net>
Why not define your functions with the list of parameters?
currentparms = {1, 4, 8};
foobar3[parmlist : {_, _, _}][x_] :=
Module[{a, b, c, d, e, f},
{a, b, c} = parmlist;
{d, e, f} = {1, 1, 1};
x a b c d e f]
foobar3[currentparms][x]
32 x
--
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/
"news.purdue.edu" <dnquark at yahoo.com> wrote in message
news:fv9jsm$50f$1 at smc.vnet.net...
> 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: Question about OneIdentity**
Next by Date:
**Re: Assigning multiple variables within a Block[] statement (e.g.**
Previous by thread:
**Re: Question about OneIdentity**
Next by thread:
**Re: Assigning multiple variables within a Block[] statement (e.g.**
| |