# newClass -- set the class and parent of an object

## setting the class and parent

• Usage:
newClass(A,B,x)
• Inputs:
• A,
• B,
• x
• Outputs:
• a copy (possibly) of x with A as class and B as parent

## setting the class

• Usage:
newClass(A,x)
• Inputs:
• A,
• x
• Outputs:
• a copy (possibly) of x with A as the new class

## common remarks

If x is a basic list or sequence, then BasicList should be an ancestor of A and B should be Nothing. If x is a hash table, then HashTable should be an ancestor of A.

If the class (and parent) of x are already equal to A (and B, respectively), then copying of the elements of x is not required, and is not done.

If x is mutable, and instances of class A are also mutable, then copying of the elements of x is not required, and is not done.

If x is not a hash table, basic list, or sequence, then its class will be set to A internally, essentially by wrapping it in a special kind of object designed solely to indicate the new class. The new class A must be a specialization of the class of x. The parent cannot be reset this way. Not all of the internal code of Macaulay2 is ready to recognize such wrapped objects, which are part of a new feature, except for the code that handles functions.

 i1 : t = 1..4 o1 = (1, 2, 3, 4) o1 : Sequence i2 : newClass(Array,t) o2 = [1, 2, 3, 4] o2 : Array i3 : x = new HashTable from { a => 1, b => 2 } o3 = HashTable{a => 1} b => 2 o3 : HashTable i4 : z = newClass(ImmutableType,Vector,x) o4 = ImmutableType{a => 1} b => 2 o4 : ImmutableType i5 : parent z o5 = Vector o5 : Type

The difference between new A of B from x and newClass(A,B,x) is that the methods installed for new are not used.

 i6 : new Thing of Thing from Thing := (A,B,c) -> ( << "-- new " << A << " of " << B << " from " << toString c << endl; c); i7 : new ImmutableType of Vector from x -- new ImmutableType of Vector from new HashTable from {a => 1, b => 2} o7 = ImmutableType{a => 1} b => 2 o7 : ImmutableType i8 : newClass(ImmutableType,Vector,x) o8 = ImmutableType{a => 1} b => 2 o8 : ImmutableType