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

MathGroup Archive 2012

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

Search the Archive

Re: How can I make a sequence that includes lists?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125521] Re: How can I make a sequence that includes lists?
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Sat, 17 Mar 2012 02:50:47 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jjrv3r$9e9$1@smc.vnet.net>

On 15/03/2012 05:35, Dana DeLouis wrote:
>> IndexedVariable[f,{{1, x1}, {2, x2}, {3, x3}...{1000, x1000}}]
>> does not work.
>
> Hi.  Not sure, but would this alternative using a dispatch table work?
>
> data = Table[{j, "x" ~~ ToString[j] }, { j,1,10000 }];
>
> dict = Dispatch[Rule@@@data];
>
> ReplaceAll[13, dict]
> x13
>
> ReplaceAll[995, dict]
> x995
>
> = = = = = = = = = =
> HTH  :>)
> Dana DeLouis
> Mac&  Math 8
> = = = = = = = = = =
>
>
>
>
> On Mar 14, 1:46 am, JasonE<ebaughja... at gmail.com>  wrote:
>> Hello folks,
>>
>> How can I make a sequence that includes lists?
>> Ex:
>> Sequence[apple, {rock, tree), {ocean, lake}]
>>
>> Here is my specific problem:
>>
>> I use this function to make associative arrays:
>> IndexedVariable[var_,indicesValues__]:=With[{dict=List[indicesValues]},Scan [(var[#[[1]]]=#[[2]])&,dict]]
>>
>> (I got it from:http://www.physic.ut.ee/~kkannike/english/prog/mathematica/index.html...)
>>
>> Here is an example of how it takes arguments:
>> IndexedVariable[f, {1, "a"}, {2, "b"}, {3, "c"}]
>>
>> In[2]:= f[1]
>> Out[2]= a
>>
>> In[3]:= f[2]
>> Out[3]= b
>> ect...
>>
>> You can imagine, some associations are too long to type out by hand.
>> Ex: {1, x1}, {2, x2}...{1000, x1000}
>>
>> When I make these associations programtically, I get a list back:
>> {{1, x1}, {2, x2},...{1000, x1000}}
>>
>> IndexedVariable[f,{{1, x1}, {2, x2}, {3, x3}...{1000, x1000}}]
>> does not work.
>>
>> It wants a sequence.
>>
>> How can I make a sequence that includes lists?
>>
>> Thanks,
>> Jason
>>
>> Jason Ebaugh
>> Contact: jasoneba... at jasonebaugh.info
>> LinkedIn:www.linkedin.com/in/jasonebaugh
>
>
To obtain a sequence from a list (which may contain sublists) simply use 
Sequence@@ - for example:

In[3]:= tmp={{1, "a"}, {2, "b"}, {3, "c"}}

Out[3]= {{1, "a"}, {2, "b"}, {3, "c"}}

In[4]:= g[Sequence@@tmp]

Out[4]= g[{1, "a"}, {2, "b"}, {3, "c"}]

David Bailey
http://www.dbaileyconsultancy.co.uk



  • Prev by Date: html posts
  • Next by Date: Re: yg = \frac{{d(yv)}}{{dt}}, how to solve this differential equation.
  • Previous by thread: Re: How can I make a sequence that includes lists?
  • Next by thread: Re: Vector Runge-Kutta ODE solver with compilation?