Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » control flow statements » return
next | previous | forward | backward | up | index | toc

return -- return from a function

Description

i1 : f = x -> (
          if x == 3 then return;
          if x > 3 then return x^2;
          5);
i2 : f 2

o2 = 5
i3 : f 3
i4 : f 4

o4 = 16

Here is an example of the use of return as a debugger command.

i5 : load "Macaulay2Doc/demos/demo1.m2"
i6 : code g

o6 = ${prefix}/share/Macaulay2/Macaulay2Doc/demos/demo1.
     m2:11:4-14:9: --source code:
     g = y -> (
          c := f(y-1);
          d := f(y-2);
          c+d)
i7 : g 2
${prefix}/share/Macaulay2/Macaulay2Doc/demos/demo1.m2:8:11:(3):[2]: error: division by zero
${prefix}/share/Macaulay2/Macaulay2Doc/demos/demo1.m2:8:11:(3): entering debugger (enter 'help' to see commands)
${prefix}/share/Macaulay2/Macaulay2Doc/demos/demo1.m2:8:
10-8:13: --source code:
     b := 1/x;
ii8 : code f

oo8 = ${prefix}/share/Macaulay2/Macaulay2Doc/demos/demo1.
      m2:6:5-9:9: --source code:
      f := x -> (
           a := "hi there";
           b := 1/x;
           b+1)
ii9 : return 1/11
${prefix}/share/Macaulay2/Macaulay2Doc/demos/demo1.m2:9:6:(3):[2]: --stepping limit reached
${prefix}/share/Macaulay2/Macaulay2Doc/demos/demo1.m2:9:6:(3): entering debugger (enter 'help' to see commands)
${prefix}/share/Macaulay2/Macaulay2Doc/demos/demo1.m2:9:5
-9:8: --source code:
     b+1)
ii10 : continue

      34
o10 = --
      11

o10 : QQ

See also

For the programmer

The object return is a keyword.


The source of this document is in Macaulay2Doc/ov_language.m2:677:0.