MathGroup Archive 2005

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

Search the Archive

Re: Re: Warning from Piecewise

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61675] Re: [mg61646] Re: Warning from Piecewise
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 25 Oct 2005 01:28:08 -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> <200510250107.VAA16782@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 25 Oct 2005, at 10:07, albert wrote:

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


Nevertheless I am right ;-)
I don't want to re-write here published material not be accused of  
plagiarism so if you have access to it check page 205 and 206 of  
David B. Wagner "Power Programming with Mathematica". If you are  
really curious and do not have the book than I can write to you  
privately about this or send you scans of these two pages.

Andrzej


  • Prev by Date: Re: Re: Warning from Piecewise
  • Next by Date: Combinations
  • Previous by thread: Re: Warning from Piecewise
  • Next by thread: Re: Re: Warning from Piecewise