www.delorie.com/gnu/docs/calc/calc_91.html   search  
 
Buy the book!


GNU Emacs Calc 2.02 Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.7.57 Rewrites Tutorial Exercise 6

Just put the rule `0^0 := 1' into EvalRules. For example, before making this definition we have:

 
2:  [-2, -1, 0, 1, 2]                1:  [1, 1, 0^0, 1, 1]
1:  0                                    .
    .

    v x 5 RET  3 -  0                    V M ^

But then:

 
2:  [-2, -1, 0, 1, 2]                1:  [1, 1, 1, 1, 1]
1:  0                                    .
    .

    U  ' 0^0:=1 RET s t EvalRules RET    V M ^

Perhaps more surprisingly, this rule still works with infinite mode turned on. Calc tries EvalRules before any built-in rules for a function. This allows you to override the default behavior of any Calc feature: Even though Calc now wants to evaluate 0^0 to nan, your rule gets there first and evaluates it to 1 instead.

Just for kicks, try adding the rule 2+3 := 6 to EvalRules. What happens? (Be sure to remove this rule afterward, or you might get a nasty surprise when you use Calc to balance your checkbook!)


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003