Example CpxVector copy 013

 

 

Description

This example shows how a CpxVector may be modified destructively or non-destructively using the the copy and setq function.

 

Details

The original CpxVector.

(setq x (new Vector: complex: 1 1.0 2.0)) Returns: #<CpxVector 123456>

The copied Vector using the copy function.

(setq z (copy x)) Returns: #<CpxVector 234567>

The copied Vector using the setq function.

(setq twin x) Returns: #<CpxVector 345678>

After the first setq function, the values of CpxVector z are:

z[0] Returns: #(cpx| #c1.0+2.0i )

After the first setq function, the value of Vector X is:

x[0] Returns: #(cpx| #c1.0+2.0i )

The container named z is a copy of x (both are Vectors) and z has a separate memory space. However, the containers named x and twin point to the same memory spaces on the heap. Therefore

(setq twin[0] #c4.0+8.0i) Returns: #<CpxVector 123456>

The setq command results in the contents of both twin and x being both the same.

twin[0] Returns: #(cpx| #c4.0+8.0i )
x[0] Returns: #(cpx| #c4.0+8.0i )

Since z points to a different memory space, it still retained the original value which was copied from x before the values of x were modified.

z[0] Returns: #(cpx| #c1.0+2.0i )

Notes and Hints

Using the setq function results in objects having the same object id. But the object that is being assigned the copied object has a different object id than original object. In this example twin and x have the same object id while z has a different object id.

 

Related Examples

Here are examples of the copy function at work.

BitVector copy 011 Brick copy 012 CpxVector copy 013 Dictionary copy 002
Directory copy 003 FltVector copy 006 IntVector copy 007 Lambda copy 008
List copy 010 Matrix copy 006 Matrix copy 007 NumMatrix copy 011
NumVector copy 008 ObjVector copy 009 Pair copy 009 PcodeVector copy 010
ShortVector copy 008 Structure copy 001 Vector copy 004 Vector copy 005

 

Function Links

Here is the link to the current function used in this example.

copy

Here are a number of links to other related functions.

setq(#void)

 

Argument Types

Here are the links to the data types of the arguments used in this example.

CpxVector

Here are a number of links to examples having similar argument types.

CpxVector addMethod 028 CpxVector append 013 CpxVector avg 002 CpxVector binaryInsert 008
CpxVector binarySearch 008 CpxVector cdr 011 CpxVector compare 020 CpxVector compareEQ 020
CpxVector compareGE 020 CpxVector compareGT 020 CpxVector compareLE 020 CpxVector compareLT 020
CpxVector compareNE 020 CpxVector copy 013 CpxVector new 015 CpxVector send 028

Analytic Information Server (AIS)

AIS Component Systems

  • Smartbase Engine
  • QT C++ Libraries
  • MySQL Relational Database
  • AIS Lisp Libraries
  • Rapid Analytic Demo IDE