User Tools


This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:update-instance-for-different-class [2019/11/11 05:00]
cl:functions:update-instance-for-different-class [2019/11/16 23:00] (current)
Line 1: Line 1:
 +====== Standard Generic Function UPDATE-INSTANCE-FOR-DIFFERENT-CLASS ======
 +  * **update-instance-for-different-class** //previous current ''&​rest''​ initargs ''&​key''​ ''&​allow-other-keys''//​ → //​[[CL:​Glossary:​implementation-dependent]]//​
 +====Method Signatures====
 +  * **update-instance-for-different-class** (//​previous//​ **[[CL:​Types:​standard-object]]**) (//​current//​ **[[CL:​Types:​standard-object]]**) //''&​rest''​ initargs//
 +====Arguments and Values====
 +  * //​previous//​ - a copy of the original //​[[CL:​Glossary:​instance]]//​.
 +  * //current// - the original //​[[CL:​Glossary:​instance]]//​ (altered).
 +  * //​initargs//​ - an //​[[CL:​Glossary:​initialization argument list]]//.
 +The generic function **update-instance-for-different-class** is not intended to be called by programmers. Programmers may write //​[[CL:​Glossary:​method|methods]]//​ for it. The //​[[CL:​Glossary:​function]]//​ **update-instance-for-different-class** is called only by the function **[[CL:​Functions:​change-class]]**.
 +The system-supplied primary //​[[CL:​Glossary:​method]]//​ on **update-instance-for-different-class** checks the validity of //​initargs//​ and signals an error if an //initarg// is supplied that is not declared as valid. This //​[[CL:​Glossary:​method]]//​ then initializes //​[[CL:​Glossary:​slot|slots]]//​ with values according to the //​initargs//,​ and initializes the newly added //​[[CL:​Glossary:​slot|slots]]//​ with values according to their **'':​initform''​** forms. It does this by calling the generic function **[[CL:​Functions:​shared-initialize]]** with the following arguments: the instance (//​current//​),​ a list of //​[[CL:​Glossary:​names]]//​ of the newly added //​[[CL:​Glossary:​slot|slots]]//,​ and the //​initargs//​ it received. Newly added //​[[CL:​Glossary:​slot|slots]]//​ are those //​[[CL:​Glossary:​local slot|local slots]]// for which no //​[[CL:​Glossary:​slot]]//​ of the same name exists in the //​previous//​ class.
 +//​[[CL:​Glossary:​method|Methods]]//​ for **update-instance-for-different-class** can be defined to specify actions to be taken when an //​[[CL:​Glossary:​instance]]//​ is updated. If only //​[[CL:​Glossary:​after methods]]// for **update-instance-for-different-class** are defined, they will be run after the system-supplied primary //​[[CL:​Glossary:​method]]//​ for initialization and therefore will not interfere with the default behavior of **update-instance-for-different-class**.
 +//​[[CL:​Glossary:​method|Methods]]//​ on **update-instance-for-different-class** can be defined to initialize //​[[CL:​Glossary:​slot|slots]]//​ differently from **[[CL:​Functions:​change-class]]**. The default behavior of **[[CL:​Functions:​change-class]]** is described in \secref\ChangingInstanceClass.
 +The arguments to **update-instance-for-different-class** are computed by **[[CL:​Functions:​change-class]]**. When **[[CL:​Functions:​change-class]]** is invoked on an //​[[CL:​Glossary:​instance]]//,​ a copy of that //​[[CL:​Glossary:​instance]]//​ is made; **[[CL:​Functions:​change-class]]** then destructively alters the original //​[[CL:​Glossary:​instance]]//​. The first argument to **update-instance-for-different-class**,​ //​previous//,​ is that copy; it holds the old //​[[CL:​Glossary:​slot]]//​ values temporarily. This argument has dynamic extent within **[[CL:​Functions:​change-class]]**;​ if it is referenced in any way once **update-instance-for-different-class** returns, the results are undefined. The second argument to **update-instance-for-different-class**,​ //​current//,​ is the altered original //​[[CL:​Glossary:​instance]]//​. The intended use of //​previous//​ is to extract old //​[[CL:​Glossary:​slot]]//​ values by using **[[CL:​Functions:​slot-value]]** or **[[CL:​Macros:​with-slots]]** or by invoking a reader generic function, or to run other //​[[CL:​Glossary:​method|methods]]//​ that were applicable to //​[[CL:​Glossary:​instances]]//​ of the original //​[[CL:​Glossary:​class]]//​.
 +See the example for the function **[[CL:​Functions:​change-class]]**.
 +====Affected By====
 +====Exceptional Situations====
 +The system-supplied primary //​[[CL:​Glossary:​method]]//​ on **update-instance-for-different-class** signals an error if an initialization argument is supplied that is not declared as valid.
 +====See Also====
 +  * **[[CL:​Functions:​change-class|Generic Function CHANGE-CLASS]]**
 +  * **[[CL:​Functions:​shared-initialize|Generic Function SHARED-INITIALIZE]]**
 +  * {\secref\ChangingInstanceClass}
 +  * {\secref\InitargRules}
 +  * {\secref\DeclaringInitargValidity}
 +//​initargs//​ are declared as valid by using the **'':​initarg''​** option to **[[CL:​Macros:​defclass]]**,​ or by defining //​[[CL:​Glossary:​method|methods]]//​ for **update-instance-for-different-class** or **[[CL:​Functions:​shared-initialize]]**. The keyword name of each keyword parameter specifier in the //​[[CL:​Glossary:​lambda list]]// of any //​[[CL:​Glossary:​method]]//​ defined on **update-instance-for-different-class** or **[[CL:​Functions:​shared-initialize]]** is declared as a valid //initarg// name for all //​[[CL:​Glossary:​class|classes]]//​ for which that //​[[CL:​Glossary:​method]]//​ is applicable.
 +The value returned by **update-instance-for-different-class** is ignored by **[[CL:​Functions:​change-class]]**.