Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » debugging » pseudocode
next | previous | forward | backward | up | index | toc

# pseudocode -- produce the pseudocode for a function

- Usage:
    `pseudocode f`
- Inputs:
  - f, a function closure
- Outputs:
  - an instance of the type PseudocodeClosure, the pseudocode of the function f

## Description

    i1 : pseudocode(() -> 2+4*3)

    o1 = function restargs false
                  numparms 0
                  framesize 0
                  frameID 12878
                  body 2-OP + 2
                              2-OP * 4
                                     3

    o1 : PseudocodeClosure

    i2 : disassemble oo

    o2 = (function restargs: false numparms: 0 framesize: 0 frameID: 12878 (2-OP
         + 2 (2-OP * 4 3)))

    i3 : pseudocode functionBody(() -> 2+4*3)

    o3 = 2-OP + 2
                2-OP * 4
                       3

    o3 : Pseudocode

    i4 : disassemble oo

    o4 = (2-OP + 2 (2-OP * 4 3))

One can look at specific part of the code by using _:

    i5 : pseudocode resolution

    o5 = function restargs true
                  numparms 1
                  framesize 1
                  frameID 199
                  body adjacent global-fetch 414
                                sequence local-fetch 1 1
                                         adjacent global-fetch 360
                                                  sequence local-fetch 0 1
                                                           local-fetch 0 0

    o5 : PseudocodeClosure

    i6 : oo_4_1_1_0

    o6 = global-fetch 360

    o6 : Pseudocode

    i7 : value oo

    o7 = override

    o7 : CompiledFunction

It may be useful to look at code during debugging, as in the following demonstration.

    i8 : load "Macaulay2Doc/demos/demo1.m2"

    i9 : code g

    o9 = /usr/share/Macaulay2/
         Macaulay2Doc/demos/demo1.m2:11:4-14:9: --source code:
         g = y -> (
              c := f(y-1);
              d := f(y-2);
              c+d)

    i10 : g 2
    /usr/share/Macaulay2/Macaulay2Doc/demos/demo1.m2:8:11:(3):[2]: error: division by zero
    /usr/share/Macaulay2/Macaulay2Doc/demos/demo1.m2:8:11:(3): entering debugger (enter 'help' to see commands)
    /usr/share/Macaulay2/
    Macaulay2Doc/demos/demo1.m2:8:10-8:13: --source code:
         b := 1/x;

    ii11 : code current

    oo11 = /usr/share/Macaulay2/
           Macaulay2Doc/demos/demo1.m2:8:10-8:13: --source code:
                b := 1/x;

    ii12 : current

    oo12 = 2-OP / 1
                  local-fetch 0 0

    oo12 : PseudocodeClosure

    ii13 : disassemble current

    oo13 = (2-OP / 1 (local-fetch 0 0))

## See also

- disassemble -- disassemble a pseudocode or function

## Ways to use pseudocode:

- pseudocode(FunctionBody) (missing documentation)
- pseudocode(FunctionClosure) (missing documentation)

## For the programmer

The object pseudocode is a compiled function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Macaulay2Doc/ov_repl.m2:1024:0.