MathGroup Archive 1999

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

Search the Archive

Re: A new symbol to "inherit" the definitions from an existing symbol?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17514] Re: [mg17464] A new symbol to "inherit" the definitions from an existing symbol?
  • From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
  • Date: Mon, 10 May 1999 19:53:19 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

I have not given this much thought and maybe I have not understood you but
it seems to me this is pretty easy. Just define a clone funtion:


clone[h_,k_]:=(OwnValues[k]=OwnValues[h]/.h->k;
    DownValues[k]=DownValues[h]/.h->k;UpValues[k]=UpValues[h]/.h->k;
 SubValues[k]=SubValues[h]/.h->k;NValues[k]=NValues[h]/.h->k;
    Attributes[k]=Attributes[h])

Now, suppose we start have a weird function f with the following rules:

In[1]:=
SetAttributes[f,Listable];L[f]^=Log[f];f/:f[x_][y_]:=f[x]+y;
f[x_*y_]:=f[x]*f[y]

Thus

In[2]:=
FullDefinition[f]
Out[2]=
Attributes[f] = {Listable}

f[x_][y_] := f[x] + y

L[f] ^= Log[f]

f[(x_) (y_)] := f[x] f[y]

Now we clone it:

In[3]:=
clone[f,g];

In[4]:=
FullDefinition[g]
Out[4]=
Attributes[g] = {Listable}

g[x_][y_] := g[x] + y

L[g] ^:= Log[g]

g[(x_) (y_)] := g[x] g[y]

Seems to work. Anything wrong?

--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp


----------
>From: Dr Phillip Kent <p.kent at ic.ac.uk>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg17514] [mg17464] A new symbol to "inherit" the definitions from an existing
symbol?
>Date: Sun, May 9, 1999, 5:44 PM
>

> A colleague just put this to me, and it seems such an obvious
> thing to do but neither of us know how to do it...
>
> I have a fairly complex (mathematical) function set up in terms
> of definitions, up values, down values, attributes, etc etc. All of
> these are directly visible with FullDefinition[]. All I want to do is
> to create a new function that immediately takes on all the definitions
> from a given function. Granted that this may be ill-defined in
> general, but let's assume that I'm going to take responsibility for the
> self-consistency of the operation.
>
> Well, I can see it's not too hard to Save[] the definitions for a
> symbol, Read[] them back in using Hold[]'s, do a substitution rule
> and release the Holds. Or, take the output cell containing the
> FullDefinition[], copy it to an input cell and process that expression.
> But, these are both bizarre procedures.
>
> Suggestions?
>
> -Phillip
>
> ----------------------------------+----------------------------
>  Dr Phillip Kent                  | tel: +44 (0)171 594 8503
>  The METRIC Project               | fax: +44 (0)171 594 8517
>  Mathematics Department           |
>  Imperial College                 | p.kent at ic.ac.uk
>  London SW7 2BZ, U.K.             | http://metric.ma.ic.ac.uk/
> ----------------------------------+----------------------------
>        "Ask not what you can do TO your data structures,
>           Ask what your data structures can do FOR you."


  • Prev by Date: Default printer: 3.0 X-windows Solaris
  • Next by Date: Re: fourier transforms
  • Previous by thread: Re: A new symbol to "inherit" the definitions from an existing symbol?
  • Next by thread: Split solution