Re: Warning from Piecewise
- To: mathgroup at smc.vnet.net
- Subject: [mg61646] Re: Warning from Piecewise
- From: albert <awnl at arcor.de>
- Date: Mon, 24 Oct 2005 21:07:03 -0400 (EDT)
- References: <FF69AAF8-0118-46DB-B123-C2DC1A80204A@mimuw.edu.pl> <200510220724.DAA12416@smc.vnet.net> <acbec1a40510221104s9e9e07cn668a994a1b3189fb@mail.gmail.com> <djfnfj$b0n$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Andrzej, > It seems to me that the Head has to be, in some sense, evaluated if a > DownValue is going to be assigned to it. Otherwise how would > Mathematica know which symbol to assign a DownValue to? > > You can see this happen here: > > SetDelayed[Print[x], p] > > SetDelayed::write: Tag Print in Print[x] is Protected > > $Failed > > Note that x was not printed but still I think we can say the head of > the expression Print[x] was evaluated. > This was why I sent my correction. sorry for complaining again :-), but I think that the head needs not be evaluated, but instead it's Attributes need to be checked, which can be done without evaluating, see the following function: SetAttributes[protectedQ, HoldAll]; protectedQ[expr_] := Module[{ head = Extract[Unevaluated[expr], 0, Hold] }, If[MatchQ[head, Hold[Symbol]], If[FreeQ[Attributes[expr], Protected], False, True] , If[FreeQ[Attributes @@ head, Protected], False, True] ] ] Now define the following symbol, which gives a clear indication when it is evaluated: Unprotect[a]; a := Throw[$Failed] Protect[a]; and see how protectedQ works: protectedQ[a[]] protectedQ[a] protectedQ[x] protectedQ[x[1]] demonstrating that we can find the Attribute without evaluating the Head. Of course the true code within SetDelayed and Set will do something slightly different and most probably is not be written in Mathematica... albert
- Follow-Ups:
- Re: Re: Warning from Piecewise
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Re: Warning from Piecewise
- References:
- Re: Warning from Piecewise
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Warning from Piecewise