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