Top
Back: 3.5.2 Special characters
Forward: 3.5.4 Objects
FastBack: 3. General concepts
FastForward: 4. Data types
Up: 3.5 The SINGULAR language
Top: Singular 2-0-4 Manual
Contents: Table of Contents
Index: F. 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 overwriting a variable is shown in the following example:

 
  int i=3;
  i=i+1;        // overwriting
  i;
→ 4
  int i=i+1;    // redefinition
→ // ** redefining i **
  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. 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.

 
  ring R;
  int n=3;
  ideal j(3);
  ideal j(n);     // is equivalent to the above
→ // ** redefining j(3) **
  ideal j(2)=x;
  j(2..3);
→ j(2)[1]=x j(3)[1]=0

Names may 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 named by the string_expression. This feature is referred to as name substitution.

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

Top Back: 3.5.2 Special characters Forward: 3.5.4 Objects FastBack: 3. General concepts FastForward: 4. Data types Up: 3.5 The SINGULAR language Top: Singular 2-0-4 Manual Contents: Table of Contents Index: F. Index About: About This Document
            User manual for Singular version 2-0-4, October 2002, generated by texi2html.