<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>newClass -- set the class and parent of an object</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_printing_spand_spformatting_spfor_spnew_spclasses.html">next</a> | <a href="_new.html">previous</a> | forward | backward | <a href="_new.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <div><a href="index.html" title="">Macaulay2Doc</a> > <a href="___The_sp__Macaulay2_splanguage.html" title="">The Macaulay2 language</a> > <a href="_new.html" title="new objects and new types">new</a> > <a href="_new__Class.html" title="set the class and parent of an object">newClass</a></div> <hr/> <div><h1>newClass -- set the class and parent of an object</h1> <div class="single"><h2>Description</h2> <div><div><h2>setting the class and parent</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>newClass(A,B,x)</tt></div> </dd></dl> </div> </li> <li>Inputs:<ul><li><span><tt>A</tt>, <span>a <a href="___Hash__Table.html">hash table</a></span></span></li> <li><span><tt>B</tt>, <span>a <a href="___Hash__Table.html">hash table</a></span></span></li> <li><span><tt>x</tt></span></li> </ul> </li> <li>Outputs:<ul><li><span>a copy (possibly) of <tt>x</tt> with <tt>A</tt> as class and <tt>B</tt> as parent</span></li> </ul> </li> </ul> </div> <div><h2>setting the class</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>newClass(A,x)</tt></div> </dd></dl> </div> </li> <li>Inputs:<ul><li><span><tt>A</tt>, <span>a <a href="___Hash__Table.html">hash table</a></span></span></li> <li><span><tt>x</tt></span></li> </ul> </li> <li>Outputs:<ul><li><span>a copy (possibly) of <tt>x</tt> with <tt>A</tt> as the new class</span></li> </ul> </li> </ul> </div> <h2>common remarks</h2> <p>If <tt>x</tt> is a basic list or sequence, then <a href="___Basic__List.html" title="the class of all basic lists">BasicList</a> should be an ancestor of <tt>A</tt> and <tt>B</tt> should be <a href="___Nothing.html" title="the empty class">Nothing</a>. If <tt>x</tt> is a hash table, then <a href="___Hash__Table.html" title="the class of all hash tables">HashTable</a> should be an ancestor of <tt>A</tt>.</p> <p>If the class (and parent) of x are already equal to A (and B, respectively), then copying of the elements of <tt>x</tt> is not required, and is not done.</p> <p>If <tt>x</tt> is mutable, and instances of class <tt>A</tt> are also mutable, then copying of the elements of <tt>x</tt> is not required, and is not done.</p> <p>If <tt>x</tt> is not a hash table, basic list, or sequence, then its class will be set to <tt>A</tt> internally, essentially by wrapping it in a special kind of object designed solely to indicate the new class. The new class <tt>A</tt> must be a specialization of the class of <tt>x</tt>. 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.</p> <table class="examples"><tr><td><pre>i1 : t = 1..4 o1 = (1, 2, 3, 4) o1 : Sequence</pre> </td></tr> <tr><td><pre>i2 : newClass(Array,t) o2 = [1, 2, 3, 4] o2 : Array</pre> </td></tr> <tr><td><pre>i3 : x = new HashTable from { a => 1, b => 2 } o3 = HashTable{a => 1} b => 2 o3 : HashTable</pre> </td></tr> <tr><td><pre>i4 : z = newClass(ImmutableType,Vector,x) o4 = ImmutableType{a => 1} b => 2 o4 : ImmutableType</pre> </td></tr> <tr><td><pre>i5 : parent z o5 = Vector o5 : Type</pre> </td></tr> </table> <p>The difference between <tt>new A of B from x</tt> and <tt>newClass(A,B,x)</tt> is that the methods installed for <a href="_new.html" title="new objects and new types">new</a> are not used.</p> <table class="examples"><tr><td><pre>i6 : new Thing of Thing from Thing := (A,B,c) -> ( << "-- new " << A << " of " << B << " from " << toString c << endl; c);</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>i8 : newClass(ImmutableType,Vector,x) o8 = ImmutableType{a => 1} b => 2 o8 : ImmutableType</pre> </td></tr> </table> </div> </div> <div class="single"><h2>See also</h2> <ul><li><span><a href="_new.html" title="new objects and new types">new</a> -- new objects and new types</span></li> <li><span><a href="_copy.html" title="copy an object">copy</a> -- copy an object</span></li> <li><span><a href="_to__List.html" title="list of elements">toList</a> -- list of elements</span></li> </ul> </div> </div> </body> </html>