MathGroup Archive 2010

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

Search the Archive

Re: How to dynamically build a list of rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109159] Re: How to dynamically build a list of rules
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Wed, 14 Apr 2010 05:16:37 -0400 (EDT)
  • References: <hq3a2h$nbr$1@smc.vnet.net>

Am 14.04.2010 04:42, schrieb janitor048:
> Hi there!
> 
> I need a somewhat larger list of substitution rules along the line of
> 
> subs = { name1 -> SomeFunction[name1], name2 ->
> SomeFunction[name2], ... , nameN -> SomeFunction[nameN]}
> 
> Obviously typing that by hand can become a little annoying. So I would
> like to have that list created dynamically, via Table[ ... ] or
> something the like.
> The problem is, I can't figure out the correct syntax for this task.
> "name1" etc. are just, well, names (variable names to be specific).
> Unfortunately I haven't been able to find a solution on the web so
> far. Any suggestions?

It's actually quite simple, so I'm not sure whether I got what your real
problem is:

namelist = {a, b, c, d}

subs = # -> SomeFunction[#] & /@ namelist

If you want to evaluate the rhs only when the lhs matches you can also use:

subs = # :> SomeFunction[#] & /@ namelist

hth,

albert


  • Prev by Date: Re: 3D interpolating
  • Next by Date: Re: How to dynamically build a list of rules
  • Previous by thread: Re: Pade Approximation (further generalizations?---feature request)
  • Next by thread: Re: How to dynamically build a list of rules