MathGroup Archive 2003

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

Search the Archive

Re: Evaluation rules and HoldRest

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42650] Re: Evaluation rules and HoldRest
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sat, 19 Jul 2003 03:19:34 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <bf8ff8$5p1$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

If[] has also the attribute HoldRest[], Evaluate[]
force the evaluation, regardless of the attribute
and so  

If[_,Evaluate[something]]

will always evaluate something because you have wrapped a Evaluate[]
around the hold argument. 

SetAttributes[Assert, HoldRest];
Assert[bool_, failedExpr_] := If[! bool, failedExpr];

and it work as expected.

Regards
  Jens


Matthias wrote:
> 
> Hello,
> 
> why is this not working as intended?
> 
> ===
> Assert[bool_, failedExpr_] := If[! bool, Evaluate[failedExpr]];
> SetAttributes[Assert, HoldRest];
> Assert[1 == 1, Print["Assertion violated!"]];
> ===
> 
> The code above prints "Assertion violated".  I know that the code behaves
> correctly when replacing ":=" by "=".  I'd like to understand why and would
> appreciate any explanation, or pointer to relevant documentation.
> 
> Thanks in advance,
> 
>   Matthias


  • Prev by Date: Re: Applying multiple functions to multiple sets of arguements
  • Next by Date: Re: Applying multiple functions to multiple sets of arguements
  • Previous by thread: Re: Evaluation rules and HoldRest
  • Next by thread: RE: Evaluation rules and HoldRest