next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc :: return

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/share/Macaulay2/Macaulay2Doc/demo1.m2:11:7-14:8: --source code:
     g = y -> (
          c := f(y-1);
          d := f(y-2);
          c+d)
i7 : g 2
/usr/share/Macaulay2/Macaulay2Doc/demo1.m2:8:12:(3):[2]: error: division by zero
/usr/share/Macaulay2/Macaulay2Doc/demo1.m2:8:12:(3):[2]: --entering debugger (type help to see debugger commands)
/usr/share/Macaulay2/Macaulay2Doc/demo1.m2:8:11-8:13: --source code:
     b := 1/x;
ii8 : code f

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

      34
o10 = --
      11

o10 : QQ

See also

For the programmer

The object return is a keyword.