MathGroup Archive 2006

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

Search the Archive

A test with options

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65414] A test with options
  • From: "Goyder Dr HGD" <h.g.d.goyder at cranfield.ac.uk>
  • Date: Fri, 31 Mar 2006 06:09:07 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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? *)

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

-- 
This message has been scanned for viruses and
dangerous content by the Cranfield MailScanner, and is
believed to be clean.


  • Prev by Date: Re: Beginner--problem with typesetting
  • Next by Date: Re: Bug with Series- help wanted
  • Previous by thread: Convex Hull 3D
  • Next by thread: Re: Bug with Series- help wanted