Example PcodeVector copy 010

 

 

Description

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

 

Details

The original Vector.

(setq x (new Vector: pcode: 5 4 )) Returns: #<PcodeVector 123456>

The copied Vector using the copy function.

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

The copied Vector using the setq function.

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

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[1] 3 ) Returns: #<PcodeVector 123456>

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

twin[1] Returns: 3
x[1] Returns: 3

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[1] Returns: 4

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.

PcodeVector

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

ByteVector new 015 PcodeVector copy 010 PcodeVector isAtom 009 PcodeVector isIdentical 016
PcodeVector isObject 011 PcodeVector isPcodeVector 001 PcodeVector length 012 PcodeVector methodsOf 020
PcodeVector new 014 PcodeVector ref 026 PcodeVector setq 023 PcodeVector sizeof 018
PcodeVector type 020

Analytic Information Server (AIS)

AIS Component Systems

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