MathGroup Archive 1995

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

Search the Archive

Re: What am I doing wrong?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2192] Re: What am I doing wrong?
  • From: ianc (Ian Collier)
  • Date: Fri, 13 Oct 1995 02:24:51 -0400
  • Organization: Wolfram Research, Inc.

In article <45d24c$63m at ralph.vnet.net>, JSNW at msg.ti.com (Jason Welter) wrote:

> Kemp[z_] := If[z>5,Kemp=gft[z] + 21,Kemp=gft[z] - 21]
> gft[z_] := If[z>5,gft=z^2 + 2,gft=z^2 - 2]
> Kemp[4]
> 
> SetDelayed::write: Tag Integer in (-14)[z_] is Protected.
> $Failed
> SetDelayed::write: Tag Integer in 7[z_] is Protected.
> $Failed
> (-14)[4]

I can't reproduce exactly what you are seeing, but I think that
your assignments to Kemp and gft withing your definitions are 
redundant and problematic.

I only see a problem when I call Kemp for the second time.

Changing the definition slightly (Kemp2 and gft2 below) 
eliminates the problem.

In your example in calling Kemp you then set the symbol Kemp 
to a certain value (after you defined the function) and this 
value is used when you attempt to call the function Kemp for 
the second time.

In[1]:=
    Kemp[z_] := If[z>5,Kemp=gft[z] + 21,Kemp=gft[z] - 21]
In[2]:=
    gft[z_] := If[z>5,gft=z^2 + 2,gft=z^2 - 2]
In[3]:=
    Kemp[4]
Out[3]=
    -7
In[7]:=
    Kemp[5]
Out[7]=
    (-7)[5]
In[4]:=
    Kemp2[z_] := If[z>5,gft2[z] + 21,gft2[z] - 21]
In[5]:=
    gft2[z_] := If[z>5,z^2 + 2,z^2 - 2]
In[6]:=
    Kemp2[4]
Out[6]=
    -7
In[8]:=
    Kemp2[5]
Out[8]=
    2

--Ian

-----------------------------------------------------------
Ian Collier
Technical Sales Support
Wolfram Research, Inc.
-----------------------------------------------------------
tel:(217)-398-0700     fax:(217)-398-0747      ianc at wri.com
Wolfram Research Home Page:             http://www.wri.com/
-----------------------------------------------------------


  • Prev by Date: Re: Help on use of Packages
  • Next by Date: Re: Inverse Z-Transform and/or Long Division
  • Previous by thread: What am I doing wrong?
  • Next by thread: String Comparison