MathGroup Archive 2007

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

Search the Archive

Re: "dereference" variable

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82077] Re: [mg82033] "dereference" variable
  • From: Todd Johnson <johnsong at ics.uci.edu>
  • Date: Thu, 11 Oct 2007 00:23:32 -0400 (EDT)
  • References: <22397821.1192019277612.JavaMail.root@m35> <op.tzzu5kmlqu6oor@monster.gateway.2wire.net>

That is true. But, as I understand it, this only works if you have the 
luxury of typing in "type[Sum[x, {i, 1, 20}]]"; if all you have is a 
local variable which has been assigned the as-yet-unevaluated expression 
"Sum[x, {i, 1, 20}]", then that solution doesn't seem to work.

todd.


DrMajorBob wrote:
> Possibly this will make it clearer:
>
> Clear[type, m, p, q, k]
> SetAttributes[type, HoldFirst];
>
> type[arg : Sum[x_, it_]] = {"Sum", HoldForm[arg], arg};
> type[arg : Times[x_, y_]] = {"Times", HoldForm[arg], arg};
> type[x_Symbol] = {"Symbol", HoldForm[x], x};
>
> m1[x_] := Module[{s = Sum[x, {i, 1, 20}]}, type[s]]
> m2[x_] := type[Evaluate@Sum[x, {i, 1, 20}]]
> m3[x_] := type[Sum[x, {i, 1, 20}]]
>
> m1[k]
> {Symbol,s$1748,20 k}
>
> m2[k]
> {Times,20 k,20 k}
>
> m3[k]
> {Sum,\!\(
> \*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(20\)]k\),20 k}
>
> m1 passes s as a symbol (setting s beforehand has no effect), m2 
> evaluates the sum to a product, and m3 passes the Sum unevaluated.
>
> Bobby
>



  • Prev by Date: Re: Matrices
  • Next by Date: Re: rule based program for "Deleting repeated members of a list."
  • Previous by thread: Re: "dereference" variable
  • Next by thread: Re: "dereference" variable