MathGroup Archive 2010

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

Search the Archive

How to delay action of ...[[i]] (Part[...,i]) until appropriate time?

Consider the following toy example:

in> goo[v_] := v.{1, 1}*(3 v)
in> foo[k_][v_] := goo[v] [[k]]

in> goo[nnn]
out> 3 nnn nnn.{1, 1}

in>foo[1][{2, 3}]

in> foo[2][nnn]

Notice how in this last output, because the parameter nnn is
undefined, [[k]] ends up acting on the structure of the expression in
goo, but the intuitive behavior would be for evaluation of [[k]] to
also be delayed.  The output I would like to see is:

out> ( 3 nnn nnn.{1,1} ) [[2]]
in> nnn = {4,5}
out> 135

But of course it does not happen that way.

I realize that Mathematica is a specification rather than procedural
language, but surely there is some reasonably elegant way to to delay
the effect of [[2]] above so it acts on the eventual result of
goo[nnn] and not on the structure of the expression.

This is related to my other questions about using NDSolve on dependent
variables that have arbitrary structure and therefore require some
kind of indexing.

There must some basic aspect of the Mathematica language that I have
missed which makes indexing and list manipulation more intuitive.  (I

Anyone have any insights?

  • Prev by Date: Re: FindRoots?
  • Next by Date: Re: Finite Groups...infinite disappoinment
  • Previous by thread: Re: Holding arguments of a family of functions
  • Next by thread: Changing from Utopia font to arial