Differences

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

Link to this comparison view

documentation:language_reference:functions:clone [2016/10/09 21:32] – created Maurits W. Haverkortdocumentation:language_reference:functions:clone [2016/10/10 09:41] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Clone ======
  
 +###
 +Clone(//a//) creates a copy of the object //a//.
 +
 +The statement $a=b$ for objects creates two variables pointing to the same object. Changing the value of one object changes the value of the other.
 +###
 +
 +===== Input =====
 +
 +  * //a// : object of any type
 +
 +===== Output =====
 +
 +  * //a'// : object of same type as //a// and an exact copy of it.
 +
 +===== Example a=b =====
 +
 +###
 +A small example showing the effect on //b// after changing //a// when //a=b//:
 +###
 +
 +==== Input ====
 +<code Quanty CloneNot.Quanty>
 +-- some example codedofile("../definitions.Quanty")
 +
 +Opp2 = Opp1 
 +Opp1.Name = "I'm the name of operator one"
 +Opp2.Name = "I'm the name of operator two"
 +print(Opp1.Name)
 +print(Opp2.Name)
 +
 +psi2 = psi1
 +psi1.Name = "I'm the name of psi one"
 +psi2.Name = "I'm the name of psi two"
 +print(psi1.Name)
 +print(psi2.Name)
 +</code>
 +
 +==== Result ====
 +<file Quanty_Output CloneNot.out>
 +I'm the name of operator two
 +I'm the name of operator two
 +I'm the name of psi two
 +I'm the name of psi two
 +</file>
 +
 +===== Example a=Clone(b) =====
 +
 +###
 +A small example showing //a=Clone(b)//:
 +###
 +
 +==== Input ====
 +<code Quanty Clone.Quanty>
 +dofile("../definitions.Quanty")
 +
 +Opp2 = Clone(Opp1) 
 +Opp1.Name = "I'm the name of operator one"
 +Opp2.Name = "I'm the name of operator two"
 +print(Opp1.Name)
 +print(Opp2.Name)
 +
 +psi2 = Clone(psi1)
 +psi1.Name = "I'm the name of psi one"
 +psi2.Name = "I'm the name of psi two"
 +print(psi1.Name)
 +print(psi2.Name)
 +</code>
 +
 +==== Result ====
 +<file Quanty_Output Clone.out>
 +I'm the name of operator one
 +I'm the name of operator two
 +I'm the name of psi one
 +I'm the name of psi two
 +</file>
 +
 +
 +===== Example a=a+b =====
 +
 +###
 +A small example showing that operations acting on objects lead to cloning the object:
 +###
 +
 +==== Input ====
 +<code Quanty CloneAuto.Quanty>
 +dofile("../definitions.Quanty")
 +
 +Opp = Opp1 + Opp2
 +Opp.Name = "I'm the name of operator Opp and different from Opp1 and Opp2"
 +print(Opp1.Name)
 +print(Opp2.Name)
 +print(Opp.Name)
 +</code>
 +
 +==== Result ====
 +<file Quanty_Output CloneAuto.out>
 +Lx
 +Ly
 +I'm the name of operator Opp and different from Opp1 and Opp2
 +</file>
 +
 +===== Table of contents =====
 +{{indexmenu>.#1}}
Print/export