next | previous | forward | backward | up | top | index | toc | packages | Macaulay2 website
Macaulay2Doc > The Macaulay2 language > making a new method function

making a new method function

The function method can be used to make new functions which execute different bits of code depending on the types of the arguments presented. Our system depends heavily on such functions.
i1 : f = method()

o1 = f

o1 : MethodFunction
We can install a method to be used when f is applied to a string as follows.
i2 : f String := s -> s|s;
i3 : f ".abcd."

o3 = .abcd..abcd.
We can check for the types of up to three arguments, too.
i4 : f(ZZ,String) := (n,s) -> concatenate (n:s);
i5 : f(5,".abcd.")

o5 = .abcd..abcd..abcd..abcd..abcd.