Macaulay2 » Documentation
Packages » Macaulay2Doc :: return
next | previous | forward | backward | up | index | toc

return -- return from a function

Synopsis

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/demo1.m2"
i6 : code g

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

oo8 = /usr/local/share/Macaulay2/Macaulay2Doc/
      demo1.m2:6:5-9:9: --source code:
      f := x -> (
           a := "hi there";
           b := 1/x;
           b+1)
ii9 : return 1/11
/usr/local/share/Macaulay2/Macaulay2Doc/demo1.m2:9:6:(3):[2]: --stepping limit reached
/usr/local/share/Macaulay2/Macaulay2Doc/demo1.m2:9:6:(3):[2]: --entering debugger (type help to see debugger commands)
/usr/local/share/Macaulay2/Macaulay2Doc/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.