procs.mws

>    foo := proc( )
   return "hello";
end proc:

>    foo();

>    foo := proc(i,j)
   local k;
   k:=sin(j);
   if i<3 then
      return i+k;
   else
      return "hello";
   end if;
end proc:

>    foo(a,b);

Error, (in foo) cannot determine if this expression is true or false: a < 3

>    foo(2,b);

2+sin(b)

>    foo(55,b);

>    # for one-liners
bar:= (i,j)->i+j;

bar := (i, j) -> i+j

>    bar(2,3);

5

>    # if there is no explicit "return",
# the returned value is that of the
# last evaluated expression:
moses:=proc(i)
  local j;
  j:=i^2;
end proc;

moses := proc (i) local j; j := i^2 end proc

>    moses(7);

49

>    # An unfortunate design decision in
# Maple that we have to live with
# is that you cannot alter the value
# of a "formal parameter", i.e. one
# of the input data (something that
# would be convenient to do in many
# instances):
test1 := proc(x,y)
   x:=3;
end proc:
test1(1,2);

Error, (in test1) illegal use of a formal parameter

>    # You can get around this like this:
test2 := proc(xx,y)
   local x;
   x:=xx;
   x:=3;
end proc:
test2(1,2);

3

>