Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: A test with options

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65434] Re: [mg65414] A test with options
  • From: "Carl K. Woll" <carlw at wolfram.com>
  • Date: Sat, 1 Apr 2006 05:38:52 -0500 (EST)
  • References: <200603311109.GAA15023@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Goyder Dr HGD wrote:
> Below I create a test with an option and a function dependant upon the
> test. As I see it the function fails to operate as I anticipated. So I
> am missing something and need help understanding. 
> 
> In[1]:=
> ClearAll[TestQ]; 
> Options[TestQ] = {EvaluationRequired -> False}; 
> TestQ[a_] := EvaluationRequired /. Options[TestQ]; 
> 
> In[4]:=
> ClearAll[f]; 
> f[(a_)?TestQ] := {100*a}
> 
> In[6]:=
> a1 = f[Cos[0]]
> 
> Out[6]=
> f[1]
> 
> In[7]:=
> (* This is as expected the function input fails the test. Now change the
> test option.*)
> 
> In[8]:=
> SetOptions[TestQ, EvaluationRequired -> True]; 
> 
> In[9]:=
> a2 = f[Cos[0]]
> 
> Out[9]=
> {100}
> 
> In[10]:=
> (* This is as expected the function input passes the test. *)
> 
> In[11]:=
> b = a1
> 
> Out[11]=
> f[1]
> 
> (* Now I am lost. Why in a new evaluation did the function input not get
> retested and pass the test? *)
> 

You need to use Update:

In[10]:=
Update[f]
b=a1

Out[11]=
{100}

> In[13]:=
> c = 100 + 100 + a1
> 
> Out[13]=
> 200 + f[1]
> 
> 
> Here are my questions
> 
> 1. Can anyone explain why the function f is not evaluated again with the
> new version of TestQ when I write b = a1 ?
> 
> 2. How can I make this work so that a function that does not evaluate,
> because the test fails, can be made to work once the test has been
> changed?
> 
> This is a toy example the background is that I wish to construct a
> function where the degree of evaluation that takes place is
> controllable.
> 
> Thanks 
> 
> Hugh Goyder
> 

Carl Woll
Wolfram Research


  • Prev by Date: Re: simplify a trig expression
  • Next by Date: Re: simultaneous nonlinear regression of a lot of data
  • Previous by thread: Re: Plot Truncation in RealTime3D
  • Next by thread: Re: A test with options