# Debugging in Yacas

##

Introduction

When writing a code segment, it is generally a good idea to separate the problem into many small functions. Not only can you then reuse these functions on other problems, but it makes debugging easier too.

The options you have for debugging a faulty function are

- Invoke the function from the command line, passing in different arguments, to see how it behaves.
- Trace

##

The trace facilities

There are two trace facilities:

- TraceExp : TraceExp traces the full expression, showing all calls to user- or system-defined functions, their arguments, and the return values. For complex functions this can become a long list of function calls.
- TraceRule : TraceRule traces one single user-defined function. It shows each invokation, the arguments passed in, and the return values. This is useful for tracking the behaviour of that function in the environment it is intended to be used in.An example invocation of TraceRule is

      In> TraceRule(x+y)2+3*5+4;

  Which should then show something to the effect of

          TrEnter(2+3*5+4);
            TrEnter(2+3*5);
                TrArg(2,2);
                TrArg(3*5,15);
            TrLeave(2+3*5,17);
              TrArg(2+3*5,17);
              TrArg(4,4);
          TrLeave(2+3*5+4,21);
      Out> 21;