Re: Table Lookup Function?
- To: mathgroup at smc.vnet.net
- Subject: [mg38619] Re: Table Lookup Function?
- From: atelesforos at hotmail.com (Orestis Vantzos)
- Date: Wed, 1 Jan 2003 03:39:45 -0500 (EST)
- References: <auqnt3$6tv$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
frankeye at cox.net (Frank Iannarilli) wrote in message news:<auqnt3$6tv$1 at smc.vnet.net>... > Hi, > > I wish to define a function as a table lookup. Here's an example: > > myFunc[i_Integer] = Table[n, {n, 1, 10}][[i]] > > so when I invoke it with an index argument i: > myFunc[3] > > it returns the 3rd element in the (precomputed) table (n.b., > "precomputed", due to defining function with Set(=) rather than > SetDelayed(:=) ). > > This works, but nonetheless, upon defining the function, Mathematica returns > the "error message": > Part::"pspec": "Part specification i is neither an integer nor a > list > of integers." > If your table is stored in myTable use: With[{aTable=myTable}, myFunc[i_?NumberQ]:=aTable[[i]] ] Orestis > I suppose I'll simply ignore this message, but is there some better > means of defining a table lookup function?