MathGroup Archive 1995

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

Search the Archive

Re: Constructing Expressions from List Elements


In article <45d02k$5tc at ralph.vnet.net>,
Lou Talman  <me at talmanl.mscd.edu> wrote:
>In[1]:=
>  q = ##&
>Out[1]=
>  ##1 &
>In[2]:=
>  limits = {{x, 0, 1}, {y, -Infinity, Infinity}, {z, 0, 1}}
>Out[3]=
>  {{x, 0, 1}, {y, -Infinity, Infinity}, {z, 0, 1}}
>In[4]:=
>   Integrate[f[x, y, z], Apply[q, limits]]
>Out[5]=
>   Integrate[f[x, y, z], {x, 0, 1}, {y, -Infinity, Infinity}, {z, 0, 1}]
>
>--Lou Talman
>

What Lou is doing is taking a List and turning it into a Sequence.
There's a more direct way to do this:

	Integrate[f[x, y, z], Sequence @@ limits]

Another nice use of this trick is when you have a list of subscripts that
you want to use as a multiple-level index into a list:

	s[[Sequence @@ subscripts]]

Note that s[[subscripts]] behaves quite differently.

You can think of Sequence@@ as an operator that obliterates the
head of the expression it is applied to.  Actually the head List
is replaced by Sequence, which subsequently is flattened.


		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon


  • Prev by Date: RE: C++
  • Next by Date: Re: Help on use of Packages
  • Previous by thread: Re: Constructing Expressions from List Elements
  • Next by thread: Re: Re: Constructing Expressions from List Elements