MathGroup Archive 2007

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

Search the Archive

Re: Re: "dereference" variable

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82119] Re: [mg82077] Re: [mg82033] "dereference" variable
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Fri, 12 Oct 2007 03:03:17 -0400 (EDT)
  • References: <22397821.1192019277612.JavaMail.root@m35> <op.tzzu5kmlqu6oor@monster.gateway.2wire.net> <28399250.1192087108813.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

> a local variable which has been assigned the as-yet-unevaluated  
> expression

No such expression can be assigned in the first place, unless you've set,  
for instance

s = Hold[Sum[x, {i, 1, 20}]]

or similarly used HoldForm (or some such), which ALSO requires that you 

"have the luxury" of typing the original, unevaluated sum. It makes no  
difference what a function can or cannot do, if you can't create the  
argument you're talking about.

Bobby

On Wed, 10 Oct 2007 23:23:32 -0500, Todd Johnson <johnsong at ics.uci.edu> 
wrote:

> 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
>>
>
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: DateListPlot question
  • Next by Date: Re: Just for fun: Shortest InputForm to achieve a given Kernel error
  • Previous by thread: Re: "dereference" variable
  • Next by thread: Re: "dereference" variable