MathGroup Archive 2005

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

Search the Archive

Re: Warning from Piecewise

  • To: mathgroup at
  • Subject: [mg61646] Re: Warning from Piecewise
  • From: albert <awnl at>
  • Date: Mon, 24 Oct 2005 21:07:03 -0400 (EDT)
  • References: <> <> <> <djfnfj$b0n$>
  • Sender: owner-wri-mathgroup at

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

a := Throw[$Failed]

and see how protectedQ works:


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...

  • Prev by Date: Accessing Elements of Arrays in TableForm
  • Next by Date: Re: Re: Unsorted Union
  • Previous by thread: Re: Re: Warning from Piecewise
  • Next by thread: Re: Re: Warning from Piecewise