# Example Matrix addMethod 008

#### Description

This example uses the added method IncAll to respond to the message IncAll which will increment each value in a Matrix.

#### Details

Define a method Increment which maps the function add1 to increment all values in the Matrix.

 (addMethod Matrix: IncAll: (lambda (s) (map add1 s))) Returns: #

Define a Matrix that contains some numbers.

 (define M #(mat| 100 200 250 150 )) Returns: #

Send the message IncAll to increment all the values in the Matrix by 1.

 (setq Y (send IncAll: V)) Returns: #

Displays the new Matrix with the incremented values.

 (display #) Returns: #(mat| 101 201 251 151 )

The method can be invoked simply by name:

 (setq Y (IncAll: M)) Returns: #

Each of the value of the modified Matrix can be accessed by specifying its index.

 Y[0] Returns: 101
 Y[1] Returns: 201
 Y[2] Returns: 251
 Y[3] Returns: 151

Notes and Hints

To view the entry in the methods Dictionary created by the addMethod function, you can use the method name to access the directory entry by

#<Dictionary 123456>[methodName:] or

To determine the number of assigned methods:

(length (methodsOf Vector: ))

To access the nth method name:

(methodsOf Vector: )[n 0]

#### Related Examples

Here are examples of the addMethod function at work.

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

Here are a number of links to other related functions.

 defmethod(#void) send(#void) methodsOf(#void)

#### Argument Types

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

 Matrix Symbol Dictionary

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