Re: Trouble with Unevaluated

• To: mathgroup at smc.vnet.net
• Subject: [mg109983] Re: Trouble with Unevaluated
• From: dh <dh at metrohm.com>
• Date: Thu, 27 May 2010 06:45:13 -0400 (EDT)
• References: <htivd3\$2a5\$1@smc.vnet.net>

```Hi Derek,
maybe I do not correctly understand what you have in mind, but it seems
to me you are trying to solve something simple very complicated.
First, TotalRevenue will return one value, therefore, an OwnValue will do.
You want to recalculate TotalRevenue  every time it is use? Well,
delayed assignment will do this.
Or do you want a display updated every time you change one of the
ingredients, e.g. Revenue[EUR]. Then Dynamic will do the job.
cheers, Daniel

Am 26.05.2010 13:07, schrieb Derek Yates:
> I think I understand how Unevaluated works, but then get stuck very
> easily. For example, here is a simplified version of something I am
> trying to do. I have the following already defined:
>
> Revenue[EUR]=4;
> Revenue[GBP]=7;
> Revenue[USD]=1;
>
> I want to create the definition TotalRevenue:=Revenue[EUR]+Revenue[GBP]
> +Revenue[USD]. I want it to be a DownValue since Revenue[EUR] may get
> changed and I want TotalRevenue to automatically update. I also want
> to create the DownValue programmatically (since the currencies as well
> as the number of currencies will change and will be an input to my
> function).
>
> My first idea was:
> assuming I already have currs={EUR,GBP,USD}
>
> With[{definition=Unevaluated[Revenue[#]]&/
> @currs},TotalRevenue:=definition]
>
> but this gives TotalRevenue:={Unevaluated[Revenue[EUR]]
> +Unevaluated[Revenue[GBP]]+Unevaluated[Revenue[USD]]}. I have to force
> evaluation using Evaluate/@TotalRevenue every time I wish to use it.
>
> (where I used Information[TotalRevenue] to examine the DownValue)
>
> I eventually found the following (which works) but feels overly
> complicated:
>
> Block[{f},
>   With[{vals = f /@ currs},
>    With[{vals2 = Hold[vals] /. f ->  Revenue},
>     With[{vals3 = Unevaluated @@ vals2}, TotalRevenue := vals3]]]]
>
> Hopefully somebody can suggest a more elegant solution.
>
>

--

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh at metrohm.com>
Internet:<http://www.metrohm.com>

```

• Prev by Date: the Operate[] function
• Next by Date: MathLink in Vista
• Previous by thread: Trouble with Unevaluated
• Next by thread: Re: Dot product confusion