|
3.7.1 Procedure definition
Example of an interactive procedure definitionproc milnor_number (poly p) { ideal i= std(jacob(p)); int m_nr=vdim(i); if (m_nr<0) { "// not an isolated singularity"; } return(m_nr); // the value of m_nr is returned } ring r1=0,(x,y,z),ds; poly p=x^2+y^2+z^5; milnor_number(p); → 4 Example of a procedure definition in a libraryFirst, the library definition: // Example of a user accessible procedure proc tab (int n) "USAGE: tab(n); (n integer) RETURNS: string of n space tabs EXAMPLE: example tab; shows an example" { return(internal_tab(n)); } example { "EXAMPLE:"; echo=2; for(int n=0; n<=4; n=n+1) { tab(4-n)+"*"+tab(n)+"+"+tab(n)+"*"; } } // Example of a static procedure static proc internal_tab (int n) { return(" "[1,n]); } Now, we load the library and execute the procedures defined there: LIB "sample.lib"; // load the library sample.lib example tab; // show an example → // proc tab from lib sample.lib → EXAMPLE: → for(int n=0; n<=4; n=n+1) → { tab(4-n)+"*"+tab(n)+"+"+tab(n)+"*"; } → *+* → * + * → * + * → * + * → * + * → "*"+tab(3)+"*"; // use the procedure tab → * * // the static procedure internal_tab is not accessible "*"+internal_tab(3)+"*"; → ? 'sample.lib::internal_tab()' is a local procedure and cannot be acce\ ssed by an user. → ? error occurred in line 5: ` "*"+internal_tab(3)+"*";` // show the help section for tab help tab; → // ** Could not get IdxFile. → // ** Either set environment variable SINGULAR_IDX_FILE to IdxFile, → // ** or make sure that IdxFile is at /home/hannes/singular/2-0/doc/singu\ lar.idx → // proc tab from lib sample.lib → proc tab (int n) → USAGE: tab(n); (n integer) → RETURNS: string of n space tabs → EXAMPLE: example tab; shows an example Guidelines for the help text of a procedureThere are no enforced rules on the format of the help section of a procedure. Nevertheless, we recommend that the help text of a procedure should contain information about the usage, purpose, return values and generated objects. Particular assumptions or limitations should be listed. It should also be mentioned if global objects are generated or manipulated. The help text of procedures contained in libraries of the SINGULAR distribution should furthermore comply with certain rules as explained in The help string of procedures. |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |