Example NumMatrix copy 011




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



The original NumMatrix.

(define x #(nummat| 21 22 23 24) ) Returns: #<NumMatrix 123456>

The copied NumMatrix using the copy function.

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

The copied NumMatrix using the setq function.

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

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

z[0] Returns: 21
z[1] Returns: 22
z[2] Returns: 23
z[3] Returns: 24

After the first setq function, the values of Matrix x are:

z[0] Returns: 21
x[1] Returns: 22
x[2] Returns: 23
x[3] Returns: 24

The container named z is a copy of x (both are Matrices) 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] 33 ) Returns: #<NumMatrix 123456>

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

twin[1] Returns: 33
x[1] Returns: 33

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

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.

Dictionary isDictionary 001 Matrix isNumberMatrix 001 Matrix objectToMatrix 001 Matrix objectToNumMatrix 001
Matrix reverse 002 NumMatrix addMethod 027 NumMatrix append 012 NumMatrix apply 009
NumMatrix binaryInsert 007 NumMatrix binarySearch 007 NumMatrix compare 023 NumMatrix compareEQ 023
NumMatrix compareGE 023 NumMatrix compareGT 023 NumMatrix compareLE 023 NumMatrix compareLT 023
NumMatrix compareNE 023 NumMatrix comparison functions 023 NumMatrix copy 011 NumMatrix count 009
NumMatrix defmethod 024 NumMatrix delete 014 NumMatrix insert 009 NumMatrix inside 009
NumMatrix isAtom 012 NumMatrix isEqual 020 NumMatrix isIdentical 020 NumMatrix isNumberMatrix 001
NumMatrix isObject 014 NumMatrix isType 022 NumMatrix length 017 NumMatrix makeGaussianMatrix 001
NumMatrix map 010 NumMatrix mapc 009 NumMatrix member 009 NumMatrix methodsOf 024
NumMatrix new 015 NumMatrix rank 002 NumMatrix ref 035 NumMatrix remove 008
NumMatrix resize 011 NumMatrix reverse 004 NumMatrix send 027 NumMatrix setCdr 013
NumMatrix setLastCdr 012 NumMatrix sizeof 028 NumMatrix sort 020 NumMatrix type 025
NumMatrix uniqueInsert 005 NumMatrix vectorFill 008 String isChar 001 String isCharAlphabetic 001
String isCharAlphanumeric 001 String isCharLowercase 001 String isCharName 001 String isCharNumeric 001
String isCharUppercase 001 String isCharWhitespace 001 String isEqual 001 String isEqual 002
String isObject 001 String isString 001 String isText 001 String isType 001
String isType 002 String isType 003 String sizeof 001 String string 001
String string 002 String string 003 String type 001 Symbol isCharName 002
Symbol isCharNumeric 002 Symbol isObject 002 Symbol isSymbol 001 Symbol isType 004
Symbol sizeof 002 Symbol type 002

How do I contact the AIS Server team?

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