MathGroup Archive 2007

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

Search the Archive

Re: functional programming

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75181] Re: functional programming
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 19 Apr 2007 04:38:11 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f04n9k$8ec$1@smc.vnet.net>

Raj wrote:
> Could somebody tell me how to do this
> 
> tsome = {{35, 38}, {2064, 2068}, {2182, 2183}};
> Select[tsome, 1280 - 1281 =E2=89=A4 #[[2]] =E2=89=A4 1280 &]
> 
> Now instead of using 1280 in the Select function, I want to use a
> variable and get the values as this variable varies. I know that a
> Table can be used and the value of the variable can be varied. But if
> possible, I want to do it in a "Truly functional way".
> 
> for example something like
> 
> Select[tsom, var-1281<=#[[2]]<=1280&]&/@{list of values over which the
> variable varies}
> 
> Thanks,
> 
> Raj
> 
> 

You could define your own function Select as in

In[1]:=
tsome = {{35, 38}, {2064, 2068}, {2182, 2183}};

mySelect[val_] := Select[tsome, val - 1281 <= #1[[2]] <= val & ]

mySelect[1280]
mySelect /@ {1280}
mySelect /@ {1280, 38}

Out[3]=
{{35, 38}}

Out[4]=
{{{35, 38}}}

Out[5]=
{{{35, 38}}, {{35, 38}}}

Regards,
Jean-Marc


  • Prev by Date: Complex bessel function
  • Next by Date: Dirac Delta Function: Basics
  • Previous by thread: Re: functional programming
  • Next by thread: Re: functional programming