MathGroup Archive 2002

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

Search the Archive

Re: how to avoid this evaluation?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37337] Re: how to avoid this evaluation?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 24 Oct 2002 02:55:25 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <ap5g9b$4l1$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

a=x^2 

is *not* a function, it is a value.
The value of a symbol is stored in
OwnValue[someSymbol]

For a you will get

{HoldPattern[a] :> x^2}

and you have to work with this form
and not with an assigment a=x^2, i.e.

SetAttributes[OwnValueString, HoldAll]

OwnValueString[from_Symbol] :=
    Module[{own, st},
    own = OwnValues[Unevaluated[from]] ;
    st = ToString[Unevaluated[from]];
    StringReplace[
      ToString[own /. HoldPattern[from] :> st /. 
          Verbatim[HoldPattern][any_] :> any, InputForm], {":>" -> "=", 
        "\"" -> ""}]
    ]

will return the string "{a=x^2}"

Regards
  Jens


elcofres wrote:
> 
> Hi,
> 
> I'm trying to write a function similar to Save, but can't find how to
> stop the main loop from evaluating the argument. Let's say I have the
> definition
> 
> a=x^2
> 
> if I do
> 
> Save[filename,a]
> 
> the definition goes into the file, what I want is to get the
> definition into a variable inside my function, so I can do:
> 
> MyFunction[a]
> 
> and within MyFunction some variable gets assigned with a=x^2 (and not
> just with x^2). Is there a way of doing this? I don't like having to
> write MyFunction["a"]. In some way Save seems to know how to tell the
> system not to replace 'a' with its value.
> 
> TIA
> Elcofres


  • Prev by Date: Pascal's Triangle
  • Next by Date: Re: how to avoid this evaluation?
  • Previous by thread: how to avoid this evaluation?
  • Next by thread: Re: how to avoid this evaluation?