MathGroup Archive 2004

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

Search the Archive

Re: Forcing Argument Evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49891] Re: Forcing Argument Evaluation
  • From: "Peltio" <peltio at twilight.zone>
  • Date: Thu, 5 Aug 2004 09:21:26 -0400 (EDT)
  • References: <ceqtgk$js9$1@smc.vnet.net>
  • Reply-to: "Peltio" <peltioNOSP at Mdespammed.com.invalid>
  • Sender: owner-wri-mathgroup at wolfram.com

"Scott Guthery" wrote

>f[x_] := x^2; a = {f,f/2};

a[[1]][2] gives 4
a[[2]][2] gives f/2[2]

>I know I'm missing something fundamental.

The source of the problem, here, is that in Mathematica any expression can
have a head that is itself an expression .

    expr = head[arg_sequence]

The head of the first expression is f and so head[2] matches f[x_].
The head of the second expression is f/2 and head[2] is Times[etc...], hence
no match for f[x_]. The evaluation of the head does not carry anywhere,
since it is done before the evaluation of the argument and of the expression
as a whole.
Of course, as you surely already know, you can operate on lists as you
wished by defining each function in a 'stand alone' manner:

    a = { #^2 &, #^2/2 &};
    a[[1]][2] gives 4
    a[[1]][2] gives 2

You would also want to take a look at the older posts in the Mathgroup on
how to implement operator algebra in Mathematica.

Cheers,
Peltio
Invalid address in reply-to. Crafty demnging required to mail me.


  • Prev by Date: 'Mathematica 5 not finding important resource'
  • Next by Date: Re: Does anybody?
  • Previous by thread: Re: Forcing Argument Evaluation
  • Next by thread: ReadListBinary question