Top
Back: Special characters
Forward: Objects
FastBack: Implemented algorithms
FastForward: Input and output
Up: The SINGULAR language
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

3.5.3 Names

SINGULAR is a strongly typed language. This means that all names (= identifiers) have to be declared prior to their use. For the general syntax of a declaration, see the description of declaration commands (see General command syntax).

See Data types, for a description of SINGULAR's data types. See typeof, for a short overview of possible types. To get information on a name and the object named by it, the type command may be used (see type).

It is possible to redefine an already existing name if doing so does not change its type. A redefinition first sets the variable to the default value and then computes the expression. The difference between redefining and overriding a variable is shown in the following example:

 
  int i=3;
  i=i+1;        // overriding
  i;
==> 4
  int i=i+1;    // redefinition
==> // ** redefining i (  int i=i+1;    // redefinition) ./examples/Names.sin\
   g:4
  i;
==> 1

User defined names should start with a letter and consist of letters and digits only. As an exception to this rule, the characters @, and _ may be used as part of a name, too (@ as the first letter is reserved for purposes of library routines). Capital and small letters are distinguished. Indexed names are built as a name followed by an int_expression in parentheses. A list of indexed names can be built as a name followed by an intvec_expression in parentheses. For multi-indices, append an int_expression in parentheses to an indexed name. An alternative multi-index construction is name_prefix( index_1, index_2,... ) where the name_prefix must be an undefined name.

 
  ring R;
  int n=3;
  ideal j(3);
  ideal j(n);     // is equivalent to the above
==> // ** redefining j(3) (  ideal j(n);     // is equivalent to the above) .\
   /examples/Names_1.sing:4
  ideal j(2)=x;
  j(2..3);
==> j(2)[1]=x j(3)[1]=0
  ring r=0,(x(1..2)(1..3)(1..2)),dp;
  r;
==> // coefficients: QQ
==> // number of vars : 12
==> //        block   1 : ordering dp
==> //                  : names    x(1)(1)(1) x(1)(1)(2) x(1)(2)(1) x(1)(2)(2\
   ) x(1)(3)(1) x(1)(3)(2) x(2)(1)(1) x(2)(1)(2) x(2)(2)(1) x(2)(2)(2) x(2)(\
   3)(1) x(2)(3)(2)
==> //        block   2 : ordering C
  int i(1,2),i(2,3);
  i(2,3);
==> 0

Names must not coincide with reserved names (keywords). Type reservedName(); to get a list of the reserved names. See reservedName. Names should not interfere with names of ring variables or, more generally, with monomials. See Identifier resolution.
The command listvar provides a list of the names in use (see listvar).

The most recently printed expression is available under the special name _, e.g.,
 
  ring r;
  ideal i=x2+y3,y3+z4;
  std(i);
==> _[1]=y3+x2
==> _[2]=z4-x2
  ideal k=_;
  k*k+x;
==> _[1]=y6+2x2y3+x4
==> _[2]=y3z4+x2z4-x2y3-x4
==> _[3]=z8-2x2z4+x4
==> _[4]=x
  size(_[3]);
==> 3

A string_expression enclosed in `...` (back ticks) evaluates to the value of the variable given by the string_expression. This feature is referred to as name substitution.

 
  int foo(1)=42;
  string bar="foo";
  `bar+"(1)"`;
==> 42


Top Back: Special characters Forward: Objects FastBack: Implemented algorithms FastForward: Input and output Up: The SINGULAR language Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 4.3.2, 2023, generated by texi2html.