Top
Back: User defined types
Forward: Declaration of objects of a user defined type
FastBack: vector
FastForward: cone
Up: User defined types
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.21.1 Definition of a user defined type

Syntax:
newstruct( name , string_expression );
newstruct( name , name , string_expression );

Purpose:
defines a new type with elements given by the last argument (string_expression). The name of the new type is the first argument (of type string) and must be longer than one character.
The second name (of type string) is an already defined type which should be extended by the new type.
The last argument (of type string) must be an comma separated list of a type followed by a name. If there are duplicate member names, the last one wins.
(User defined) member names are restricted to alphanumeric charecters and must start with a letter.

Operations:
the only operations of user defined types are:
assignment (between objects of the same or extended type)
typeof
string and printing
operator . to access the elements

Example:
 
  newstruct("nt","int a,poly b,string c");
  nt A;
  nt B;
  A.a=3;
  A.c=string(A.a);
  B=A;
  newstruct("t2","nt","string c");
  t2 C; C.c="t2-c";
  A=C;
  typeof(A);
==> t2
  A;
==> c=t2-c
==> c=
==> b=??
==> a=0
  // a motivating example ------------------------------------------
  newstruct("IDEAL","ideal I,proc prettyprint");
  newstruct("HOMOGENEOUS_IDEAL","IDEAL","intvec weights,proc prettyprint");
  proc IDEAL_pretty_print(IDEAL I)
  {
    "ideal generated by";
    I.I;
  }
  proc H_IDEAL_pretty_print(HOMOGENEOUS_IDEAL I)
  {
    "homogeneous ideal generated by";
    I.I;
    "with weights";
    I.weights;
  }
  proc p_print(IDEAL I) { I.prettyprint(I); }
  ring r;
  IDEAL I;
  I.I=ideal(x+y2,z);
  I.prettyprint=IDEAL_pretty_print;
  HOMOGENEOUS_IDEAL H;
  H.I=ideal(x,y,z);
  H.prettyprint=H_IDEAL_pretty_print;
  H.weights=intvec(1,1,1);
  p_print(I);
==> ideal generated by
==> _[1]=y2+x
==> _[2]=z
  p_print(H);
==> homogeneous ideal generated by
==> _[1]=x
==> _[2]=y
==> _[3]=z
==> with weights
==> 1,1,1


Top Back: User defined types Forward: Declaration of objects of a user defined type FastBack: vector FastForward: cone Up: User defined types Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 4-0-3, 2016, generated by texi2html.