MathGroup Archive 2003

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

Search the Archive

Re: Convert list into function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41545] Re: Convert list into function
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Mon, 26 May 2003 05:46:24 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 5/24/03 at 1:05 AM, rajb at stanford.edu (rbhatnagar) wrote:

>A simple question: What is the correct way of converting a list into a
>function?

>For instance, lets say I have some list L = {1, 2, 3, 4}

>and I want a function such that FuncL[1] would return 1, FuncL[2]
>would return 2 and so on.  So what is the syntax for FuncL?

>I need the function for some further manipulation in a situation in
>which simply using L[[1]] would not be appropriate.

The most obvious syntax (at least to me) is

FuncL[x_]:=L[[x]]

Perhaps somewhat better would be either

FuncL[x_, list_]:= list[[n]]

since this doesn't require a global definition of L to pre -exist. But this last is no different in effect than simply renaming the built in function Part, i.e.

Part[L,x] results in L[[x]]


  • Prev by Date: Re: Simple 3D plot of two points
  • Next by Date: Re: slowing down on windows XP
  • Previous by thread: Re: Convert list into function
  • Next by thread: RE: Convert list into function