a question about [[ ]]
- To: mathgroup at smc.vnet.net
- Subject: [mg46578] a question about [[ ]]
- From: Paolo Bientinesi <pauldj at cs.utexas.edu>
- Date: Tue, 24 Feb 2004 21:04:27 -0500 (EST)
- Organization: University of Texas at Austin
- Sender: owner-wri-mathgroup at wolfram.com
Hello,
here is what I am trying to do:
g is a function that invokes f.
f[x] is undefined,
while f[{x,y}] returns a list, say {f[x],f[y]} (or any other list).
Assume
f[{x_, y_}] := { f[x], f[y] }
and
g[x_] := {f[x][[1]], f[x][[2]]}
I would like to have
In := g[a]
Out:= {f[a][[1]], f[a][[2]]}
and
In := g[{b,c}]
Out:= {f[b], f[c]}
Rationale: function g has the knowledge that f iv evaluated return a list.
If f is not evaluated I want the symbolic expression to be returned.
The problem is the first case: g[a].
I cannot prevent Mathematica from evaluating f[a][[1]]
returning the unwanted a.
For f[a][[2]] the situation is slightly better because after the mesg
Part::"partw": "Part \!\(2\) of \!\(f[a]\) does not exist."
Mathematica return the unevaluated expression f[a][[2]].
Basically I would like Mathematica to evaluate (Something)[[ ]]
only is Something is a list and leave everything symbolic otherwise.
Thanks for any suggestion.
--
Paolo
pauldj at cs.utexas.edu paolo.bientinesi at iit.cnr.it