Home Online Manual
Top
Back: proc expression
Forward: resolution
FastBack: poly
FastForward: resolution
Up: proc
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.16.3 procs with different argument types

Syntax:
branchTo ( string_expression , ... proc_name )
Purpose:
branch to the given procedure if the argument types matches the types given as strings (which may be empty - matching the empty argument list). The main procedure (p in the example) must be defined without an argemnt list, and branchTo statement must be the first statement within the procedure body.
Example:
 
  proc p1(int i) { "int:",i; }
  proc p21(string s) { "string:",s; }
  proc p22(string s1, string s2) { "two strings:",s1,s2; }
  proc p()
  { branchTo("int",p1);
    branchTo("string","string",p22);
    branchTo("string",p21);
    ERROR("not defined for these argument types");
  }
  p(1);
==> int: 1
==>    ? branchTo(...) failed
==>    ? error occurred in or before ./examples/procs_with_different_argument\
   _types.sing line 14: `;return();`
  p("hu");
==>    skipping text from ` ` error at token `)`
  p("ha","ha");
==> two strings: ha ha
==>    ? branchTo(...) failed
==>    ? error occurred in or before ./examples/procs_with_different_argument\
   _types.sing line 16: `;return();`
  p(1,"hu");
==>    skipping text from ` ` error at token `)`

See proc.