MathGroup Archive 2005

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

Search the Archive

Re: Re: Warning from Piecewise


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

> Hi,
>
>
>> Actually Set and SetDelayed are special functions and their behaviour
>> in this sort of situation is not determined by their attributes. You
>> can see the difference as follows. First, let us create a function H,
>> to which we give the Attribute HoldAll.
>>
>
> I absolutely agree that Set and SetDelayed are special functions,  
> but to
> understand the behaviour in regard to the "partial" evaluation I  
> think they
> are not so special at all. Any function that has the Attribute  
> HoldAll can
> extract parts of the unevaluated expressions an evaluate just these  
> parts.
> Look at the following example:
>
> SetAttributes[evaluatepartssometimes, HoldAll]
>
> evaluatepartssometimes[x_, val_] := Module[{head, args},
>     Switch[Head[Unevaluated[x]],
>       Symbol, {Hold[x],{}, Hold[val]},
>       _,
>       head = Extract[Unevaluated[x], 0, Hold];
>       args = Extract[Unevaluated[x], #] & /@ Range[Length 
> [Unevaluated[x]]];
>
>       {head, args, Hold[val]}
>       ]
>     ]
>
> this should behave very similar to SetDelayed concerning the  
> evaluation of
> it's first argument (although I don't know the exact rules of  
> evaluation
> for SetDelayed).
>
> e.g.:
>
> a=1
> evaluatepartssometimes[a[Print["hello"]; 1 + 1, 3 - 4], 1 + 4]
> evaluatepartssometimes[a, 1 + 4]
>
> or am I missing your point?
>
> albert
>
>

No, of course,I agree with you and never meant anything else. I when  
I wrote that SetDelayed and Set are "special functions" I was  
actually referring to the fact that they evaluate their arguments in  
a "special way" (not relying on the "Evaluator" that evaluates  
arguments of functions without Hold attributes). Other built in  
functions also do that, for example Plot etc, though of course there  
are many different kinds of "special".

Andrzej Kozlowski


  • Prev by Date: Re: Complex numbers in Mathematica
  • Next by Date: Re: Re: Warning from Piecewise
  • Previous by thread: Re: Warning from Piecewise
  • Next by thread: Re: Warning from Piecewise