Example NumVector copy 008




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



The original Vector.

(define x #(num| 11.433 -2.6 )) Returns: #<NumVector 123456>

The copied Vector using the copy function.

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

The copied Vector using the setq function.

(setq twin x) Returns: #<NumVector 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.6 ) Returns: #<NumVector 123456>

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

twin[1] Returns: 3.6
x[1] Returns: 3.6

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: -2.6

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 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.


Here are a number of links to other related functions.



Argument Types

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


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

BitVector bitToNumberVector 001 BitVector inside 007 NumVector addMethod 021 NumVector append 008
NumVector apply 007 NumVector binaryInsert 006 NumVector binarySearch 007 NumVector bitToNumberVector 002
NumVector cdr 008 NumVector compare 016 NumVector compareEQ 014 NumVector compareGE 014
NumVector compareGT 014 NumVector compareLE 014 NumVector compareLT 014 NumVector compareNE 014
NumVector comparison 014 NumVector copy 008 NumVector defmethod 019 NumVector delete 011
NumVector insert 007 NumVector inside 006 NumVector isAtom 007 NumVector isEqual 015
NumVector isIdentical 014 NumVector isNumberVector 001 NumVector isObject 009 NumVector isType 018
NumVector length 010 NumVector map 007 NumVector mapc 007 NumVector member 006
NumVector methodsOf 019 NumVector new 011 NumVector objectToNumVector 001 NumVector ref 024
NumVector remove 006 NumVector resize 008 NumVector reverse 005 NumVector send 017
NumVector setCdr 008 NumVector setLastCdr 008 NumVector setq 021 NumVector sizeof 016
NumVector sort 015 NumVector svmRegression 001 NumVector type 018 NumVector uniqueInsert 006
NumVector vectorBinaryInnerProduct 001 NumVector vectorBipolarInnerProduct 001 NumVector vectorCosineInnerProduct 001 NumVector vectorCubeInnerProduct 001
NumVector vectorExpInnerProduct 001 NumVector vectorFill 005 NumVector vectorInnerProduct 001 NumVector vectorLogInnerProduct 001
NumVector vectorQuartInnerProduct 001 NumVector vectorQuintInnerProduct 001 NumVector vectorSigmoidInnerProduct 001 NumVector vectorSineInnerProduct 001
NumVector vectorSquareInnerProduct 001 NumVector vectorTanInnerProduct 001 NumVector vectorTanhInnerProduct 001 ObjVector cdr 009
ObjVector sort 016

How do I contact the AIS Server team?

You can always talk with the AIS at aiserver.sourceforge.net.