Example ShortVector copy 008

 

 

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.

(define x #(short| 11 12 )) Returns: #<ShortVector 123456>

The copied Vector using the copy function.

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

The copied Vector using the setq function.

(setq twin x) Returns: #<ShortVector 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: #<ShortVector 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: 12

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.

ShortVector

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

ShortVector addMethod 021 ShortVector append 008 ShortVector apply 007 ShortVector binaryInsert 006
ShortVector binarySearch 007 ShortVector cdr 008 ShortVector compare 016 ShortVector compareEQ 015
ShortVector compareGE 015 ShortVector compareGT 015 ShortVector compareLE 015 ShortVector compareLT 015
ShortVector compareNE 015 ShortVector comparison functions 015 ShortVector copy 008 ShortVector defmethod 019
ShortVector delete 011 ShortVector insert 007 ShortVector inside 006 ShortVector isAtom 007
ShortVector isEqual 015 ShortVector isIdentical 014 ShortVector isObject 009 ShortVector length 010
ShortVector map 007 ShortVector mapc 007 ShortVector member 006 ShortVector methodsOf 019
ShortVector new 011 ShortVector ref 024 ShortVector remove 006 ShortVector resize 008
ShortVector reverse 005 ShortVector send 017 ShortVector setCdr 008 ShortVector setq 021
ShortVector sizeof 016 ShortVector sort 015 ShortVector type 018 ShortVector uniqueInsert 007
ShortVector vectorFill 005

Analytic Information Server (AIS)

AIS Component Systems

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